Let me say say straight away that although I am good at Access/Excel VBA I am pretty new to Outlook VBA.
I need to be able to retrieve the email address of the sender of an arbitrary email, and have come across two ways of doing it. One is obvious, the other is written by Microsoft (slightly adapted). They both return the same result at least some of the time. I want a reliable method, and suspect MS knows somwthing I don't...
My simple and obvious approach is:
Function SenderEmail_old(oM As Outlook.MailItem)
SenderEmail_old = oM.SenderEmailAddress
However, I admit to having problems with the above, which sometimes returns what looks like an obscure X.400 type of string, or part of one. (Maybe it had something to do with the email being forwarded.)
Microsoft's piece of contorted obfuscation is (adapted from the Otlook 2013 help):
Function SenderEmail(oM As Outlook.MailItem) As String
' return sender of email object oM
Dim oPA As Outlook.PropertyAccessor
Dim oContact As Outlook.ContactItem
Dim oSender As Outlook.AddressEntry
Dim SenderID As String
'Create an instance of PropertyAccessor
Set oPA = oM.PropertyAccessor
'Obtain PidTagSenderEntryId and convert to string
SenderID = oPA.BinaryToString _
'Obtain AddressEntry Object of the sender
Set oSender = Application.Session.GetAdd
SenderEmail = oSender.Address
Can anyone inform what is so great about the second approach?? Is it more reliable? Consistent? How does it work?
Final question: Are there any problems with using either of these in Outlook 2003?
I am amazed that something like this can be so un-straightforward, and utterly mystified by what is going on with the BinaryToString argument (oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C190102
Yours seeking enlightenment