Kooki
Kooki

Reputation: 1157

Get Message-ID after send mail

For my outlook addin I need to handle emails, calculate an unique hash and store this hash on a server/database. For example :

There are 4 users :

Case 1:

User1 sends a mail to User2 and User3. User2 wants to store the mailhash serverside, so he clicks an addin button. A hash is calculated with code like this

var accessor = mailItem.PropertyAccessor;
var subject = accessor.GetProperty(_PR_SUBJECT_W_TAG).ToString();
var messageId  = accessor.GetProperty(_PR_INTERNET_MESSAGE_ID_W_TAG).ToString();
var hash = CalulateHash(subject + messageId);

This hash is stored on the server. If User3 tries to store the hash of the mail too, he gets the same hash (cause subject and messageid should be the same ==> rfc822) and the server knows, he got this hash already. This works very well.

Case 2: User1 wants to send a mail to User2,User3 and randomperson. Cause randomperson doesn't belong to their company, User1 want to use the function SendAndStore(). Before the mail is send, a custom property is added to the new mail

mailItem.UserProperties.Add("HandleAfterSent", MSOutlook.OlUserPropertyType.olText);
var aasProp = mailItem.UserProperties.Find("HandleAfterSent");
if (aasProp != null)
{
    aasProp.Value = "some_value";
}
mailItem.Save();

SendMailItem(mailItem);

Moreover, there is a possibility to get notified if a new item is added to a inboxfolder. So I observe the sent folder.

inbox = outlookNameSpace.GetDefaultFolder(MSOutlook.OlDefaultFolders.olFolderSentMail);
items = inbox.Items;
items.ItemAdd += OnInboxItemAdded;

If the mail is send via SendMailItem(mailItem);, the handler is called (works fine too). But unfortunately I have problems with calculating the hash of the send mail, cause this mail has no Message-ID. Does anyone have a idea, how to get the Message-ID of a mail, which was send just now. I already tried to set the Message-ID on my own, but it is overriden from MS Exchange server.

EDIT : Outlook is on cache mode. I need a possibility to get the Message-ID for this scenario too.

EDIT2 (in addition to comments) : Case 3: randomperson wants to send a mail to User1,User2 and User3. Cause randomperson doesn't belong to their company, User1 want to use the function StoreFromInbox(). Mails in the inbox of all three Users have the same Message-ID. But they have different _PR_SEARCH_KEY_ , so we can't use this property.

Upvotes: 0

Views: 2218

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

Try to use PR_SEARCH_KEY MAPI property - it should stay the same after the message is sent and moved to the Sent Items folder.

Upvotes: 1

Related Questions