We are offering our consulting services for all types of projects related to Visual Basic, Outlook, Exchange Server and other Microsoft environments. If you are looking for a high-quality company to provide outstanding consulting services to your organization, email us at consult@codeoftheweek.com
If you are interested in advertising in COTW (our rates are VERY reasonable), please email us at sponsor@codeoftheweek.com
The source code in this issue is designed for Visual Basic 4.0 and higher.
This issue enhances the class from issue #21. It discusses using a class to send a simple email message directly from Visual Basic using the MAPISession and MAPIMessages controls that ship with Visual Basic. This issue adds the ability to send attachments using the MAPI controls.
You will need to add the MAPI custom control to your project to use this class. In Visual Basic 5.0 you would perform the following steps:
This class requires that you drop a MAPISession and MAPIMessages control onto your form after you add the control to your project.
Public Enum eRecipType
List of enumerated types that are used with the AddRecipient method.
Public Property Set MAPISessionControl(ctl As Control)
Assign this property the MAPISession control that you dropped onto your form.
Public Property Set MAPIMessageControl(ctl As Control)
Assign this property the MAPIMessage control that you dropped onto your form.
Public Sub ComposeMessage(sSubject As String, sMsg As String)
Starts the message creation process. sSubject will be the Subject of the message and sMsg will be the message body.
Public Sub AddRecipient(sName As String, eType As eRecipType)
Allows you to add multiple receipients to send the message composed by ComposeMessage. sName is the email address and eType is either RecipTypeTo or RecipTypeCC, which corresponds to the To: field and the CC: field in an email message.
Public Sub AddAttachment(sAttachmentName As String, sFilename As String)
Allows you to add any number of attachments to the message. The only limitation seems to be that the filenames must be different (at least with the Outlook 98 client).
Public Sub SendMessage()
Sends the message composed with the above three methods.
There are certain assumptions taken in this class. For example, it automatically signs you onto the email system (We tested with Eudora Pro and Outlook 98) when you assign the MAPISessionControl property.
This is a simple example that will send an email message to our info address at info@codeoftheweek.com with a CC to coolstuff@codeoftheweek.com. It assumes the MAPISession control on your form is called MAPISess and the MAPIMessages control is called MAPIMsg. It will also append three attached data files.
Dim MAPI As New cMAPI Set MAPI.MAPISessionControl = MAPISess Set MAPI.MAPIMessageControl = MAPIMsg MAPI.ComposeMessage "Order for Code of the Week", _ "Please send me Code of the Week as soon as you can." MAPI.AddRecipient "info@codeoftheweek.com", RecipTypeTo MAPI.AddRecipient "coolstuff@codeoftheweek.com", RecipTypeCC MAPI.AddAttachment "Credit Card Info.txt", "c:\visa.txt" MAPI.AddAttachment "Credit Card Info2.txt", "c:\visa2.txt" MAPI.AddAttachment "Credit Card Info3.txt", "c:\visa3.txt" MAPI.SendMessage Set MAPI = Nothing
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0090.html