Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sender's email address in Outlook

Status
Not open for further replies.

TheBitDoctor

Programmer
Nov 28, 2003
59
0
0
US
I've diverted a set of messages into a folder based on the subject line. Now I want to search a database using the senders email address but I can't get to the information I need using Outlook VBA. I'm using this code:

Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim InboxFolder As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim MsgItem As Outlook.MailItem
Dim TheBody As String
Dim SenderEmail As String

Set ns = ol.GetNamespace("MAPI")
Set InboxFolder = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = InboxFolder.Folders("Diverted Msgs")
For Each MsgItem In SubFolder.Items
SenderEmail = MsgItem.SenderName
TheBody = MsgItem.Body

... look up senders email address in database

Next MsgItem


The problem I'm having is with the SenderName or SentOnBehalfOfName properties. On those messages with a text prefix ie "FirstName Lastname" <First.Last@somewhere.com> all these fields contain is the quoted portion and I need the actual email address inside the angle brackets. The information I need is in the "Return-Path" field of the email message header but Outlook VBA doesn't seem to provide access to either the message header or the <...> portion of the from field.

Does anyone know a consistent method for finding the email address that a message was sent from using Outlook VBA?
 
Have you tried this ?
SenderEmail = MsgItem.SenderEmailAddress
You may discover the Outlook object model guard security warning ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH:

What version of Outlook are you using. I'm using Outlook 2000 and it doesn't support the 'SenderEmailAddress' property for the Outlook.MailItem message object. That would be too logical and much too easy for billy boy! And, yes I do run into the $%^&%^*#@ security warning for scripts within Outlook. How can you run automated events within Outlook when you force the user to be sitting in front of the machine ready to answer a dialog box?!?!

Thanks,
Ron
 
What version of Outlook are you using
2003
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top