Advanced Features

The MAPI controls do offer some features beyond simply sending and receiving messages. These features are the message class, requesting a receipt, tracking a conversation thread, and displaying a recipient’s properties.

The Message Class

All MAPI messages have a message class, which is a string that broadly differentiates types of messages. The MsgType property of the MAPIMessages control gives you access to the message class. The most common message class is IPM.Note, which signifies a generic email message. If you leave the MsgType property blank when composing a message, MAPI automatically gives the message a class of IPM.Note.

A common use of message classes is to tell the receiving mail client that a custom form should be used when displaying the message. For example, if you’ve created a custom form in Outlook, Outlook uses that form when displaying any message with a message class of IPM.Note. FormName (where FormName is the name you gave to the form). Be aware that if the receiving mail client doesn’t recognize the message class, it will likely complain to the user, who may not know what the problem is.

To send a message using a custom message class, you must be sending to a recipient that is capable of receiving messages in Microsoft Exchange RTF, and the recipient’s address book entry must indicate this fact, as shown in Figure 4-7.

If you are writing an application that reads and responds to messages only of a certain class, you may want to set the FetchMsgType property prior to calling the Fetch method. By setting this property equal to the desired class, you ensure that you fetch only messages of that class.

Setting Microsoft Exchange RTF for an email address

Figure 4-7. Setting Microsoft Exchange RTF for an email address

Requesting a Receipt

To be notified when your sent message has been read by a recipient, set the MsgReceiptRequested property to True. The mail system on the target computer replies automatically to such messages to let you know when the user has received the message.

You can also read the value of this property on a received message to determine if the sender requested a receipt. However, you do not need to generate the receipt yourself—MAPI does that for you. Also, you won’t ever find this MAPI-generated outgoing message in your Outbox or Sent Items folders. MAPI simply sends the receipt message on its way.

The Conversation ID

The MsgConversationID property of the MAPIMessages control can be used to keep track of a conversation thread. A conversation thread is a set of messages made up of an original message plus the replies to that message.

The Microsoft documentation for this property states that new messages are assigned an ID by the message system. This is true when sending new mail using the MAPI controls, but new mail sent by other means may not generate a conversation ID. The conversation ID for new mail generated by Microsoft Outlook 98, for example, is blank. This means that you can’t count on all messages having a conversation ID.

In addition, the conversation ID may get lost in transit. For example, messages sent via the Internet lose their conversation ID value, unless you are sending to a recipient that is capable of receiving messages in Microsoft Exchange RTF and the recipient’s address book entry indicates this fact, as shown in Figure 4-7.

The MsgConversationID property is a string, and although it’s possible to set this value yourself when composing a message, you’ll find that the value you set isn’t carried through to the receiving system, regardless of how you send it. Therefore, you should leave it blank, which allows the mail system to set it for you. When you reply to or forward a message, the mail system automatically copies the original conversation ID into the conversation ID property of the new message.

Showing Properties of a Message Recipient

In Microsoft Outlook, you can right-click a recipient and view that recipient’s properties. You can code a similar feature into your own applications by using the MAPIMessages control’s Show method, with an argument of True. This causes the mail system to display its properties dialog box for the currently indexed recipient. The user can make changes in this dialog box if desired and if the user has sufficient security rights to do so. (The user may not have rights to modify the Global Address List [GAL], for example.) If the user cancels this dialog box, a mapUserAbort error is raised in your code.

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.