Get MessageID of a sent mail in Outlook

倾然丶 夕夏残阳落幕 提交于 2019-12-23 02:06:09

问题


I'm currently writing on an Outlook VSTO AddIn. Using this AddIn, I would like to keep track of E-Mail conversations and be able to uniquely identify mail messages. We are using Exchange as MTA.

For all the mails in the Inbox (and many other folders) I can use the Message ID from the mail's header to do the matching, but mails lying in the "Sent Items" folder do not have a Message ID set.

Is there a way to get the Message IDs from those mails?

(I guess that the mails do not have a header, as they are placed in the folder before being sent; but after sending the mail, the MTA gives a message with status code 250 which contains the Message ID.) Does Outlook know about or somehow save the MessageID? How can Outlook keep track of conversations, if it doesn't know the MessageID? Is there another way to identify a mail?


回答1:


First let us clarify why do you mean by

Is there another way to identify a mail

Actually you can duplicate an email then, they will have the same MessageID but different ItemId. If you have multiple recipients: toms@gmail.com, toms@an.exchange.mailbox.com, toms2@an.exchange.mailbox.com they will have the same MessageID (aka InternetMessageId) even the first one is not even Exchange. For the two others, there are two different messages within the same Exchange server. The have differents ItemID(aka EntryId).

Conclusion, the MessageID identifies the mail from its content and is set by the mailserver sending the email. To my knowledge there is no alternative (except creating your own "digest") from the immutable properties of an email. Keep also in mind that 'ItemId' changes when you move an email from a folder to another. See

For a VSTO add-in you can retrieve the MessageID aka InternetMessageId using Redemption. The other alternative is to ask the ExchangeServer using MAPI or EWS. In all cases there will be a 'server call' and it cannot be retrieve directly after sending because this property is set by Exchange Mail server.




回答2:


Exchange always assigns message ids to all existing emails even if they are not sent. The problem is the id might not be visible in the cached mode as MSEMS provider tries to minimize network traffic and does not sync the data from the Sent Items folder since the cached store has "almost" the same copy.

You can reopen the message from the Sent Items folder in the online mode by specifying the MAPI_NO_CACHE flag (0x0200) when calling IMsgStore::OpenEntry and then reading the PR_INTERNET_MESSAGE_ID property (0x1035001F).

If Extended MAPI is not an option (it can only be used from C++ or Delphi), you can use Redemption and its RDOSession.GetMessageFromID method which allows to (optionally) specify the flags:

 set YourMailItem = Application.ActiveExplorer.Selection(1)

 MAPI_NO_CACHE = &H0209
 MAPI_BEST_ACCESS = &H0010

 set Session = CreateObject("Redemption.RDOSession")
 Session.MAPIOBJECT = Application.Session.MAPIOBJECT
 set Mail = Session.GetMessageFromID(YourMailItem.EntryID, , MAPI_NO_CACHE + MAPI_BEST_ACCESS)
 MsgBox Mail.Fields("http://schemas.microsoft.com/mapi/proptag/0x1035001F")


来源:https://stackoverflow.com/questions/42291195/get-messageid-of-a-sent-mail-in-outlook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!