Thomas
Thomas

Reputation: 605

Message Id (PR_INTERNET_MESSAGE_ID_W_TAG) Not Available in Event Handler After Sending An Email

I have an instance of Microsoft.Office.Interop.Outlook.Application and I add itemSendHandler to the Application.itemSend

Application.itemSend += itemSendHandler

I'm assuming inside the itemSendHandler, the email should already be sent and a Message Id should exist for the email. Yet the following code produces a null messageId:

private void itemSendEventHandler(object sentItem, ref bool Cancel)
}
    string PR_INTERNET_MESSAGE_ID_W_TAG = "http://schemas.microsoft.com/mapi/proptag/0x1035001F";
    PropertyAccessor propertyAccessor = ((MailItem)sentItem).PropertyAccessor;
    // This is null? Why?
    string messageId = (string)propertyAccessor.GetProperty(PR_INTERNET_MESSAGE_ID_W_TAG);
    ThisAddIn.attemptToReleaseComObject(propertyAccessor);   
{

But when I inspect the sent item immediately afterwards, through the code or through a tool (like OutlookSpy or MFCMAPI), the property exists. Why is messageId null during the send event handler?

Upvotes: 1

Views: 625

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66316

You need to save the message first before accessing that property. Even then, PR_INTERNET_MESSAGE_ID might not be accessible in the cached mode - Outlook will not synchronize the item in the Sent Items folder with its online replica for the performance reasons, and only the online version of the message will have that property. You can open that message in the online mode using Extended MAPI (C++ or Delphi) or Redemption (any language) by using the MAPI_NO_CACHE flag, but there is no way to do that in OOM.

Upvotes: 1

Related Questions