Sending Mail
Sending a text message programmatically is simple. Assuming that you’ve already signed on with the MAPISession control and that you’ve set the MAPIMessages control’s SessionID property equal to the MAPISession control’s SessionID property, the following code does the job:
With MAPIMessages1 .Compose .MsgSubject = "This is the subject." .MsgNoteText = "This is the message body." .RecipIndex = 0 .RecipDisplayName = "Dave" .Send End With
Calling the MAPIMessages control’s Compose method tells the control that you are about to set some properties for a new outgoing message. Unlike incoming messages, there can never be more than one outgoing message at a time. The value of the MsgIndex property for the outgoing message is -1.
The MsgSubject and MsgNoteText properties are self-explanatory, being the subject and body portions of the message, respectively.
Unlike composing a message, there is no explicit method to call for adding a recipient, and the RecipIndex property is never -1. The number of recipients is controlled by how you set the RecipIndex property. In the code shown previously, the act of setting RecipIndex to automatically causes RecipCount to become 1. RecipCount is always automatically one greater than the highest value to which you have set RecipIndex. You never set RecipCount directly. The previously shown code can be modified to send to two recipients as follows:
With MAPIMessages1 .SessionID = MAPISession1.SessionID .Compose .MsgSubject = "This is the subject." ...