none
[E2010] [EWS] [C#]: How to get the actual SMTP address that an email was sent to internally? RRS feed

  • Question

  • Hi,

    I'm sending an email address internally to Exchange 2010 using a secondary SMTP address.

    When I analyse this email using the EWS API, looking at the ToRecipients, the address that is returned is the primary SMTP address.

    I saw another thread suggesting to look at the InternetMessageHeaders, but this info was not there.

    I need to see the actual address that was used to send the email to.

    How can I access this?

    Thanks,

    Rob


    • Edited by Rob.Ford Thursday, April 12, 2012 12:36 AM
    Thursday, April 12, 2012 12:20 AM

Answers

  • First thing i would suggest you do is look at one of the messages with a Mapi editor like OutlookSpy of MFCMapi this will allow you to see all the raw properties that are available on a message. Generally the Hub will have resolved the proxy address back to the primary so this information is lost (in 2007 it did used to get stored in the recipients collection but this isn't accessible via EWS anyway).

    You should be able to the Get the Transport headers from the PR_Transport_header extended property which should allow you the parse the original headers out eg (you can also use the Mapi editor to view the contents of this property before you start) the reason the InternetHeaders don't work is explained in http://msdn.microsoft.com/en-us/library/hh545614(v=exchg.140).aspx

                ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String);
                PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_TRANSPORT_MESSAGE_HEADERS,ItemSchema.MimeContent };
                
                FindItemsResults<Item> fiResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(1));
                foreach (Item itItem in fiResults.Items) {
                    itItem.Load(psPropSet);
                    Object valHeaders = null;
                    if (itItem.TryGetProperty(PR_TRANSPORT_MESSAGE_HEADERS, out valHeaders)) {
                        Console.WriteLine((String)valHeaders);
                    }
                    
    
                }

    Otherwise the other thing would be to look at MimeContent of the message which should also contain the original headers.

    Cheers
    Glen

    • Marked as answer by Rob.Ford Thursday, April 12, 2012 8:13 PM
    Thursday, April 12, 2012 5:18 AM

All replies

  • First thing i would suggest you do is look at one of the messages with a Mapi editor like OutlookSpy of MFCMapi this will allow you to see all the raw properties that are available on a message. Generally the Hub will have resolved the proxy address back to the primary so this information is lost (in 2007 it did used to get stored in the recipients collection but this isn't accessible via EWS anyway).

    You should be able to the Get the Transport headers from the PR_Transport_header extended property which should allow you the parse the original headers out eg (you can also use the Mapi editor to view the contents of this property before you start) the reason the InternetHeaders don't work is explained in http://msdn.microsoft.com/en-us/library/hh545614(v=exchg.140).aspx

                ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String);
                PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_TRANSPORT_MESSAGE_HEADERS,ItemSchema.MimeContent };
                
                FindItemsResults<Item> fiResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(1));
                foreach (Item itItem in fiResults.Items) {
                    itItem.Load(psPropSet);
                    Object valHeaders = null;
                    if (itItem.TryGetProperty(PR_TRANSPORT_MESSAGE_HEADERS, out valHeaders)) {
                        Console.WriteLine((String)valHeaders);
                    }
                    
    
                }

    Otherwise the other thing would be to look at MimeContent of the message which should also contain the original headers.

    Cheers
    Glen

    • Marked as answer by Rob.Ford Thursday, April 12, 2012 8:13 PM
    Thursday, April 12, 2012 5:18 AM
  • Thanks for your help, Glen. Both of your suggested methods work. However, the actual address is only available if the mailbox is hidden from the address list and Outlook cannot see it to resolve it and change it to the primary address. The mailbox I need to use can't be hidden. I'll have to think of another way to achieve what I need :)
    Thursday, April 12, 2012 8:15 PM