VB and VBA Users Source Code: Returning a Sender's email address from an Outlook Mailitem
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Returning a Sender's email address from an Outlook Mailitem
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, May 30, 2005
Hits:
3060
Category:
Unspecified
Article:
The code below takes an Outlook Mailitem and uses MAPI objects to return the sender's email address. Note, an Outlook Mailitem supports the SenderName property but doesn't expose any properties to return the sender's email address. 'Purpose : Returns the email address for an Outlook Mailitem. 'Inputs : oOutlookMail The outlook message to return the email address of. 'Outputs : Returns the email address of the specified outlook message. 'Author : Andrew Baker 'Date : 25/03/2000 'Notes : Function GetMailItemSenderAddress(oOutlookMail As Outlook.MailItem) As String Dim oMapiMessage As Object 'MAPI.Message Dim oSession As Object 'MAPI.Session Dim sEntryID As String Dim sEntryID As String Set oSession = CreateObject("MAPI.Session") 'Logon to the existing session oSession.Logon "", "", False, False 'Get the message Information sEntryID = oOutlookMail.EntryID sEntryID = oOutlookMail.Parent.StoreID 'Get the message Set oMapiMessage = oSession.GetMessage(sEntryID, sEntryID) 'Extract the Sender's Address and Return value GetMailItemSenderAddress = oMapiMessage.Sender.Address oSession.Logoff Set oSession = Nothing Set oMapiMessage = Nothing Exit Function ErrFailed: Debug.Print Err.Description Debug.Assert False GetMailItemSenderAddress = "" End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder