How to get Sender Email Address from MailItem in Exchange Accounts?

For getting Sender Email of a MailItem in POP3/SMTP accounts if pretty easy. We can get that by olMailItem.SenderEmailAddress. But, for Exchange Accounts, its  a bit different. We need to get the AddressEntry first and then get the SMTP Address from that object. Here is a sample code that I framed for simpler understanding.

Dim objSender As Outlook.Recipient = Nothing
Dim objPropXR As Outlook.PropertyAccessor = Nothing
Dim strSMTPAddress As String = “”
Dim strSenderEntryID As String = “”
Dim objNS As Outlook.NameSpace = Nothing
Dim objAE As Outlook.AddressEntry = Nothing
Dim objEU As Outlook.ExchangeUser = Nothing

objNS = Globals.ThisAddIn.Application.GetNamespace(“MAPI”)
objPropXR = objMail.PropertyAccessor
strSenderEntryID = objPropXR.BinaryToString(objPropXR.GetProperty(“http://schemas.microsoft.com/mapi/proptag/0x0C190102”))
objSender = objNS.GetRecipientFromID(strSenderEntryID)
objAE = objSender.AddressEntry
If objAE.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry Then
objEU = objAE.GetExchangeUser
strSMTPAddress = objEU.PrimarySmtpAddress
Else
strSMTPAddress = objAE.Address
End If
MessageBox.Show (“Sender Email Address: ” & strSMTPAddress)

objMailItem is an object of Outlook.MailItem
Hope this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *