none
Do Exchange emails always include SMTP addresses in the headers? RRS feed

  • Question

  • Hello, I just posted this question on StackOverflow but am looking for additional expertise and visibility. Apologies if that's a faux pas! https://stackoverflow.com/questions/49242751/do-exchange-emails-always-include-smtp-addresses-in-the-headers

    Here are the basic questions I have about Outlook add-in development:

    1. Are SMTP MIME headers available for all mail items? Even "internal" Exchange emails (Exchange user to Exchange user)?

      I'm using the following code to get the headers, but I'm not sure if it's reliable:

      mailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");
       
    2. Do these headers always include valid, SMTP email addresses in the From:, CC:, and similar fields? For example:
      From: "Darth Vader" <dvader@empire.com>
      To: "Palpatine" <palps@empire.com>
      CC: "Boba Fett" <boba@empire.com>, "IG-88" <ig88@empire.com>, "Bossk" <bossk@empire.com>

      As opposed to Active Directory Distinguished Names, like...

      From: /O=EMPIRE PARTNERS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=VADER, DARTHBC4 TO: /O=EMPIRE PARTNERS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=PALPSBC4


    And here's more context to clarify these questions:

    I'm developing an Outlook Add-in that displays alongside each email in Outlook. It is a sidebar that shows information about all the participants in the current email thread. My add-in requires the SMTP email addresses of the participants.

    This is all fine - unless the users on the thread are Exchange users. In that case, Outlook does not give me direct access to their SMTP address. I have to follow a process similar to this post: Extract SMTP address from Exchange User in the FROM field of a message

    String addressString = null;
    
    try
    {
        ExchangeUser exchangeUser = address.GetExchangeUser();
        if (exchangeUser != null)
        {
            addressString = exchangeUser.PrimarySmtpAddress;
        }
    } catch {
    
    }
    
    if (addressString == null)
    {
        addressString = address.Address;
    }
    
    

    The problem with this is, if the user's Exchange Server connection is broken or laggy, then resolving this User to an SMTP address can be slow. It can even freeze Outlook entirely.

    So back to my original questions - Can I reliably expect the Email headers to be available, and if so, do those headers always contain valid SMTP email addresses?

    Thanks for any advice.



    • Edited by Jay Ty Monday, March 12, 2018 7:21 PM And still, more bad code formatting
    Monday, March 12, 2018 7:20 PM

Answers

  • No, PR_TRANSPORT_MESSAGE_HEADERS will not always be available. It is only set if the message was converted to MIME and delivered through the SMTP connector. That will not be the case for the messages delivered between on-prem Exchange mailboxes within the same domain.

    If I were you, I would

    1. cache the addresses - people tent to correspond with the same people

    2. In most cases, the SMTP address is directly available on the message itself. E.g. there is the PidTagSenderSmtpAddress_W (DASL name http://schemas.microsoft.com/mapi/proptag/0x5D01001F) for the sender and PR_SMTP_ADDRESS (DASL name http://schemas.microsoft.com/mapi/proptag/0x39FE001F) for the recipeints. The first can be accessed using MailItem.PropertyAccesssor.GetProperty, and the second one using Recipient.PropertyAccesssor.GetProperty. You can see these properties in OutlookSpy (click IMessage button).

    3. Multitasking is not supported by the Outlook Object Model, but you can do that in Extended MAPI (C++ or Delphi) or the RDO family of objects in Redemption (any language).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Jay Ty Monday, March 12, 2018 8:54 PM
    Monday, March 12, 2018 7:36 PM

All replies

  • No, PR_TRANSPORT_MESSAGE_HEADERS will not always be available. It is only set if the message was converted to MIME and delivered through the SMTP connector. That will not be the case for the messages delivered between on-prem Exchange mailboxes within the same domain.

    If I were you, I would

    1. cache the addresses - people tent to correspond with the same people

    2. In most cases, the SMTP address is directly available on the message itself. E.g. there is the PidTagSenderSmtpAddress_W (DASL name http://schemas.microsoft.com/mapi/proptag/0x5D01001F) for the sender and PR_SMTP_ADDRESS (DASL name http://schemas.microsoft.com/mapi/proptag/0x39FE001F) for the recipeints. The first can be accessed using MailItem.PropertyAccesssor.GetProperty, and the second one using Recipient.PropertyAccesssor.GetProperty. You can see these properties in OutlookSpy (click IMessage button).

    3. Multitasking is not supported by the Outlook Object Model, but you can do that in Extended MAPI (C++ or Delphi) or the RDO family of objects in Redemption (any language).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Jay Ty Monday, March 12, 2018 8:54 PM
    Monday, March 12, 2018 7:36 PM
  • Thanks so much for the response Dmitry! I've marked yours as the correct answer on StackOverflow.

    Re: Item 2

    When you say "in most cases", do you mean depending on Exchange server version / configuration, or are there some other variables that affect this?

    Secondly, would you recommend using the header proptag (PR_TRANSPORT_MESSAGE_HEADERS) as a fallback in case PidTagSenderSmtpAddress_W and/or PR_SMTP_ADDRESS are empty? Or is it not worth the effort?

    Thanks in advance.

    Monday, March 12, 2018 8:56 PM
  • I was just trying to point out that you should not expect these properties to be present. Older versions of Exchange (2007 and 2010) are a particular concern.

    PR_TRANSPORT_MESSAGE_HEADERS would probably take precedence over AddressEntry.GetExchangeUser.PrimarySmtpAddress if performance is your main concern.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, March 13, 2018 12:00 AM