0
votes

Is it possible to determine the Exchange Server ItemID for a MailItem (the selected Item in the active explorer)? The solution I am working on has an Outlook AddIn component and another component that accesses mail items through EWS.

I have code similar to the below in my Outlook addin:

Outlook.Explorer ActiveExplorer = Globals.ThisAddIn.Application.ActiveExplorer();
object selectedItem = ActiveExplorer.Selection[1];
Outlook.MailItem selectedEmail = selectedItem as Outlook.MailItem;

In this way I can access certain properties of the email but it is important to the workings of the overall solution that the property values are exactly the same as those returned by EWS. For example, if the property returned a time, it would be important that the time matched down to the millisecond.

If I had the ItemID I could bind to and work with the Item (from within the addin) using something like the below.

Item myItem = Item.Bind(MyExchangeService, MyItemID);

On a whim I have tried binding to MailItem.EntryID but I got a malformed ID error (which didn't surprise me). I have been trying to determine if the Exchange ID was available through MailItem.PropertyAccessor.GetProperty but I am not really familiar with accessing properties in this way and haven't had any luck so far.

Thoughts?

1

1 Answers

2
votes

I came across the following Stack Overflow post which didn't exactly answer my question but changed my focus to converting the EntryID into the EWS ID rather than finding the EWS ID.

Exchange ItemID differs from GlobalAppointmentID for Outlook AddIn

With this new angle I was able to find the following site which directly addressed my issue.

https://bernhardelbl.wordpress.com/2013/04/15/converting-entryid-to-ewsid-using-exchange-web-services-ews/

I have posted the code here in full in case the link gets broken.

string ConvertHexEntryIdToEwsId(ExchangeService esb, string sID, string strSMTPAdd)
{
    AlternateId objAltID = new AlternateId();
    objAltID.Format = IdFormat.HexEntryId;
    objAltID.Mailbox = strSMTPAdd;
    objAltID.UniqueId = sID;

    AlternateIdBase objAltIDBase = esb.ConvertId(objAltID, IdFormat.EwsId);
    AlternateId objAltIDResp = (AlternateId)objAltIDBase;
    return objAltIDResp.UniqueId;
}