Solved

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

Posted on 2014-10-21
4
154 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Resolve DNS query failed errors for Exchange
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
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…
how to add IIS SMTP to handle application/Scanner relays into office 365.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now