0
votes

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" <[email protected]>
    To: "Palpatine" <[email protected]>
    CC: "Boba Fett" <[email protected]>, "IG-88" <[email protected]>, "Bossk" <[email protected]>
    

    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.

1
"do those headers always contain valid SMTP email addresses"? No. I can write some buggy code and send out an email with address = some gibberish and your server will still pick it up. And depending on the mail server you have it might or might not drop the mailSteve
Thanks for the reply. I'm not concerned about edge cases or misuse like that. So to clarify, I'm wondering about everyday use, with valid SMTP messages (i.e. not malformed). And the mail server in question is Exchange. So would Exchange ever simply not send the headers and SMTP address, even if they're technically valid?Jimmie Tyrrell

1 Answers

0
votes

A copy of my reply from the MSDN forum @ https://social.msdn.microsoft.com/Forums/en-US/2f0bd7b7-1865-42d1-9b17-86d5d91b15c1/do-exchange-emails-always-include-smtp-addresses-in-the-headers?forum=outlookdev


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 recipients. 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).