Le Café Central de Deva
let.us.share.develop.more... Deva blogs!!
Recently I was assisting an developer who used Outlook Object Model (OOM) API and tried to get the SMTP address of the Sender of a given mail item. In order to get the values, he first made the following OOM call – it worked fine for him for couple of mail items, but fails to get the SMTP value as given below:
/O=MFC2013/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=B370134F8FFD4CF3A0023F27B6B61F7D-ADMINISTRATOR
In this scenario, to determine the SMTP address for a mail item, you can use the SenderEmailAddress property of the MailItem object. However, if the sender is internal to your organization, SenderEmailAddress does not return an SMTP address, and you must use the PropertyAccessor object to return the sender’s SMTP address (adding the related C#.Net code for your reference).
1: private string GetSMTPAddress(Outlook.MailItem mail)
3: string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
4: if (mail.SenderEmailType == "EX")
6: Outlook.AddressEntry sender =
8: if (sender != null)
10: //Now we have an AddressEntry representing the Sender
11: if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry
12: || sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
14: //Use the ExchangeUser object PrimarySMTPAddress
15: Outlook.ExchangeUser exchUser = sender.GetExchangeUser();
16: if (exchUser != null)
18: return exchUser.PrimarySmtpAddress;
22: return null;
27: return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
32: return null;
37: return mail.SenderEmailAddress;
This will help you to move ahead and get the correct SMTP address:
Does not work for Outlook 2007 because MailItem.Sender does not exist.