Solved

Getting the SMTP email address of an email's sender in Outlook

Posted on 2014-10-21
4
162 Views
Last Modified: 2014-10-23
Hello Experts

I am having problems retrieving the sender of an email in Outlook 2010 - in some cases.

at the moment I am using the following code - courtesy of BlueDevilFan  (see
this link) to get the address back:

Function GetSMTPAddress(olkMsg As Outlook.MailItem) As String
    Dim olkSnd As Outlook.AddressEntry, olkExu As Outlook.ExchangeUser
    Set olkSnd = olkMsg.Sender
    If olkSnd.AddressEntryUserType = olExchangeUserAddressEntry Then
       Set olkExu = olkSnd.GetExchangeUser
        GetSMTPAddress = olkExu.PrimarySmtpAddress

    Else
        GetSMTPAddress = olkMsg.SenderEmailAddress
    End If
    Set olkSnd = Nothing
    Set olkExu = Nothing
End Function

However, there are some cases (just 2 cases out of 75 in my initial testing) where this just returns an empty string.

On stepping through the code, the cases are both ones where the AddressEntryUser Type equals
OLExchangeUserAddressEntry (i.e. the lines in bold get executed).

Can anyone out there explain why this happens and how to get the proper SMTP address back, as opposed to the X400 Exchange address? Or is it just that the sending Exchange server has been badly configured?

Thanks in advance.

Hopeful Kiwi
0
Comment
Question by:kiwi_731
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
sinfocomar earned 500 total points
ID: 40395298
Blue..'s script is somewhat lacking. Please try this one:

http://www.gregthatcher.com/Scripts/VBA/Outlook/GetSmtpAddress.aspx
0
 

Author Comment

by:kiwi_731
ID: 40399603
Hi sinfocomar

The script you linked to works beautifully. The intractable cases now produce the correct output via the GetSmtpAddress = exchangeUser.PrimarySmtpAddress line of code.

I admit to being nonplussed as to how the routine works; however, it works. Delving into the depths of MAPI etc is a task for another day. (Why did they have to make it so complicated?)

Many thanks

Hopeful Kiwi
0
 

Author Closing Comment

by:kiwi_731
ID: 40399618
Good solution, a bit light on details, but not to worry.

Hopeful Kiwi
0
 
LVL 11

Expert Comment

by:sinfocomar
ID: 40399747
Sorry for the lightness :) all I knew was the script worked...

Microsoft seems to not like revealing the inner workings of Outlook (wonder why...). Pity as it was supposed to be an open PIM for third parties to add their stuff... We should be neck deep in code and plugins by now that do these things. Also not every MAPI property is exposed to VBA but only MFC if you want to read some look here: http://www.slipstick.com/developer/read-mapi-properties-exposed-outlooks-object-model/

Thx for the points!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you don't know how to downgrade, my instructions below should be helpful.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question