
outlook 2000 - getting a mail's mail address
Quote:
> I am writing an application, where one part of the application is written
> using the Outlook 2000 object model and visual basic. The script is quite
> small, and the task is simple: whenever a new mail arrives, get the
senders
> e-mail address, and process it in some way. The problem is, it seems to be
> impossible to retrieve the e-mail address of the sender. Only the name is
> available (mailItem.sender). However, it seems unreasonable to me if it is
> not possible to get the address in some way. Anyone got a hint?
> Thanks in advance,
> Thorvald Boe
The following routine does the job bit requires a reference to Microsofts
CDO.dll . I posted a question about this myself last week but nobody knew
the answer. Finally found it in an obscure place on the net. The objMailItem
parameter is an Outlook mailitem object. I have tested this and it works
fine:
Private Function Sender_Address(objMsg As MailItem) As String
'-----------------------------
Dim strEntryID As String
Dim strStoreID As String
Dim objSession As MAPI.Session
Dim objCDOItem As MAPI.Message
'-----------------------------
On Error Resume Next
'------------------------------------
' get EntryID and StoreID for message
'------------------------------------
strEntryID = objMsg.EntryID
strStoreID = objMsg.Parent.StoreID
'------------------
' start CDO session
'------------------
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False
'----------------------------------------
' pass item to CDO and get sender address
'----------------------------------------
Set objCDOItem = objSession.GetMessage(strEntryID, strStoreID)
Sender_Address = objCDOItem.Sender.Address
Set objSession = Nothing
Set objCDOItem = Nothing
End Function