How to get the smtp email address located on the left of the "on behalf of" address

I would like to get the email address from the true contact that is sending the mailItem. I don't want the on behalf email address.

Is there a way to do that?

Outlook mailItem example

enter image description here

This is my code:

Function GetSenderSMTPAddress(ByRef olkMailItem As Outlook.MailItem) As String
    Dim olkSender As AddressEntry
    Set olkSender = olkMailItem.sender

    GetSenderSMTPAddress = GetSMTPAddress(olkSender)
End Function

Function GetSMTPAddress(ByRef olkAddress As AddressEntry) As String
    Dim smtpAddress As String: smtpAddress = olkAddress.Address
    Dim olkExUser As ExchangeUser
    
    If olkAddress.AddressEntryUserType = olExchangeUserAddressEntry Or _
    olkAddress.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then
        Set olkExUser = olkAddress.GetExchangeUser
    End If
    
    If Not IsNull(olkExUser) Then
        smtpAddress = olkExUser.PrimarySmtpAddress
    End If
    
    GetSMTPAddress = smtpAddress
End Function


Read more here: https://stackoverflow.com/questions/68463059/how-to-get-the-smtp-email-address-located-on-the-left-of-the-on-behalf-of-addr

Content Attribution

This content was originally published by Marcos Churi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: