Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ShellExecute to send mail using the default mail program
KeywordsShellExecute, mail, email, cc, bcc
CategoriesOffice
 
Use the ShellExecute API function to "open" a statement of the form (all on one line):

    mailto:ann@msn.com
        ?cc=bob@msn.com
        &bcc=cindy@msn.com
        &subject=Hi
        &body=Hello there!

To embed carriage return/line feed combinations in the message body, use the hexadecimal values %0D and %0A.

 
Private Sub cmdSend_Click()
    ShellExecute hwnd, _
        "open", _
        "mailto:" & txtTo.Text & _
        "?cc=" & txtCc.Text & _
        "&bcc=" & txtBcc.Text & _
        "&subject=" & txtSubject.Text & _
        "&body=" & Replace(txtMessage.Text, vbCrLf, _
            "%0D%0A"), _
        vbNullString, vbNullString, _
        SW_SHOW
End Sub
 
The result of all this is to pop up the system's default mail application with the indicated fields filled in. This works with VB 6 and Outlook Express. Other mail applications may not understand all of these fields.


Markus Seitz adds:

There seems to be a little variation in the way Win2K and WinNt4 interpret things as well. The same shell mail generated (in Outlook2K) has about 9 lines in Win2K and only 5 in WinNT4.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated