Fill In the E-Mail Fields ShellExecute is one of the most flexible Win32 APIs. Using ShellExecute, you can pass any filename, and if the file’s extension is associated to a registered program on the user’s machine, the correct application opens and the file is played or displayed. In the February 1998 101 Tech Tips supplement, Jose Rodriguez Alvira showed ShellExecute’s Internet power («Create Internet-Style Hyperlinks»). If you pass an HTTP URL, the user’s default 32-bit Web browser opens and connects to the site. If you pass an e-mail address that has been prefaced with «mailto:», the user’s default 32-bit e-mail client opens a new e-mail note with the address filled in. Here’s how to automatically get a lot more than just the e-mail addresses filled in. If you want to include a list of CC recipients, BCC recipients, or your own subject text or body text, you can create a string variable, add the list of primary addresses (separated by semicolons), then a question mark character and element strings prefaced like this: For CCs (carbon copies): &CC= (followed by list) For blind CCs: &BCC= (followed by list) For subject text: &Subject= (followed by text) For body text: &Body= (followed by text) To add an attachment: &Attach= (followed by a valid file path within chr(34)’s) To use this trick, create a new VB project, add a form, and add six textboxes and a button (cmdSendIt). Paste this into the form’s Declarations section: 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 Private Const SW_SHOWNORMAL = 1 Paste this code into the button’s Click event: Private Sub cmdSendIt_Click() Dim sText As String Dim sAddedText As String If Len(txtMainAddresses) Then sText = txtMainAddresses End If If Len(txtCC) Then sAddedText = sAddedText & "&CC=" & txtCC End If If Len(txtBCC) Then sAddedText = sAddedText & "&BCC=" & txtBCC End If If Len(txtSubject) Then sAddedText = sAddedText & "&Subject=" & txtSubject End If If Len(txtBody) Then sAddedText = sAddedText & "&Body=" & txtBody End If If Len(txtAttachmentFileLocation) Then sAddedText = sAddedText & "&Attach=" & _ Chr(34) & txtAttachmentFileLocation & Chr(34) End If sText = "mailto:" & sText ' clean the added elements If Len(sAddedText) <> 0 Then ' there are added elements, replace the first ' ampersand with the question character Mid$(sAddedText, 1, 1) = "?" End If sText = sText & sAddedText If Len(sText) Then Call ShellExecute(Me.hWnd, "open", sText, _ vbNullString, vbNullString, SW_SHOWNORMAL) End If End Sub You can’t have spaces between the ampersands and tags, or between the tags and the equal signs. You don’t have formatting options, so body text will be one paragraph. However, when you use this technique, program errors are e-mailed to you with full details, and you can create real e-mail applets in a just a few seconds. It beats automating a full e-mail program. In addition, almost all this functionality is possible in HTML MailTo tags. Here is a sample: <A HREF="mailto:smith@smithvoice.com?subject= Feedback From VisualBasic ett smithvoice.com/vbfun.htm&CC=smith@smithhome.org&BC C=fred@fred.net;bill@home.com&body=hello how are you">feedback@smithvoice</A> I have yet to get HTML to do the attachments, but attachments are no problem in VB. Editor’s Note: The full functionality of these extra fields is available in e-mail clients that are totally Exchange-compliant. Some or all of the extra fields might not work with noncompliant e-mail clients.