Solved

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

Posted on 2014-10-21
4
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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