Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No explicit Outlook instance??

Status
Not open for further replies.

fumei

Technical User
Oct 23, 2002
9,349
CA
Hi there. I found the following code in file sent to me for another reason. I am wondering why this works.
Code:
'Used for creating an e-mail
Private Declare Function ShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long

Sub MakeMessage()
Dim sText As String, _
   sSubject As String, _
   sBody As String, _
   sWhoTo As String

sWhoTo = "fumei@BlahBlah.net"
sSubject = "Subject line text"
sBody = "Body text.  Body text."

sText = "mailto: " & sWhoTo & "?Subject=" & _
      sSubject & "&Body=" & sBody
'Send e-mail
Call ShellExecute(0&, "open", sText, vbNullString, vbNullString, -1)
End Sub
This creates an Outlook message with the named fields completed. I have adjusted the text a little...my address is not fumei@BlahBlah.net

But it works. Outlook is NOT open. I do not have Outlook loaded. Yet this creates a process of Outlook.exe and the message. Just the message. The main Outlook application does not appear. Only the message.

Could someone explain how this is working to me? Hitting Send does indeed send the message. Why have I been creating instances of Outlook (and MAPI object, MailItem object...yadda yadda yadda), if this makes messages so simply?

What is going on here?

Gerry
My paintings and sculpture
 
A simpler way to do the same thing:
CreateObject("WScript.Shell").Run Chr(34) & sText & Chr(34)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The mailto: hyperlink launch the create new message window of the default mail client (in your case Outlook, in mine Outlook Express)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
So the API, or the WScript, parses the initial "mailto:" of the string and makes a message with the registered default mail client?

Gerry
My paintings and sculpture
 
My understanding is that the mailto URL is parsed by the default mail client itself.
Have a look at the HKEY_CLASSES_ROOT\mailto registry key.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ah thank you. But would not Wscript have to parse the string in order to determine to even send it to the mail client? How else would it know to pass it to th email client?

In any case, thank you. I think I have a better grasp on this.

Gerry
My paintings and sculpture
 
would not Wscript have to parse the string
I don't think so.
I'd say that the Run method of the WshShell object is mainly a high level wrapper to the ShellExecute API call.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top