Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
outlook error send and receive 15 93
Exchange 2016 Services 1 31
Powershell Command for Distribution Lists 2 32
exchange 2007 5 15
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
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: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

685 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