Skip to Content
CDO & MAPI Programming with Visual Basic:
book

CDO & MAPI Programming with Visual Basic:

by Dave Grundgeiger
October 2000
Intermediate to advanced
384 pages
10h 22m
English
O'Reilly Media, Inc.
Content preview from CDO & MAPI Programming with Visual Basic:

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." ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
COM Programming with Microsoft® .NET

COM Programming with Microsoft® .NET

John Paul Mueller, Julian Templeman

Publisher Resources

ISBN: 156592665XSupplemental ContentCatalog PageErrata