View Single Post
  #3  
Old November 1st 06, 07:13 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 1,643
Default determining Senders smtp address

The messages are different because you are assuming that the item you are
processing is the last in the folder (objMessages.GetLast). Firstly, the
physical order of the messages has absolutely to with the message sort order
in the Outlook.
Secondly, you need to retrieve the message using Session.GetMessage:

Set objMessage = objSession.GetMessage(objInboxEmail.EntryID,
objInboxEmail.Parent.StoreID)

Thirdly, need to use the AddressEntry.Type property (= "EX" for the Exchange
addresses) rather than rely on the "/o=" substring
Fourthly, PR_SMTP_ADDRESS (0x39FE001E) is not available in the cached mode
in Outlook 2003, you need to use PR_EMS_AB_PROXY_ADDRESSES instead
(multivalued string property).

plug
in Redemption the code will be as simple as

set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = objInboxEmail
if not (sItem.Sender is Nothing) Then
MsgBox sItem.Sender.SMTPAddress
End If

/plug

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Paul Young" wrote in message
news
I am trying to obtain the smtp address of a message selected by our
Servicedesk staff using the code:

Set objOutlook = CreateObject("Outlook.Application")
Set objActiveExplorer = objOutlook.ActiveExplorer
Set objInboxEmail = objActiveExplorer.Selection(1)
strSender = objInboxEmail.SenderEmailAddress

This returns the smtp address for internet messages but the distinguished
name of exchange users.

I've found code to get the smtp address for a message using CdoPR_EMAIL
value.

Public Const CdoPR_EMAIL = &H39FE001E

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False, 0
' Get first message from inbox
Set objFolder = objSession.Inbox
Set objMessages = objFolder.Messages
Set objMessage = objMessages.GetLast()

' Get address
Set objAddressEntry = objMessage.Sender
strEMailAddress = objAddressEntry.Address

' Check if it is an Exchange object
If Left(strEMailAddress, 3) = "/o=" Then

' Get the SMTP address
strAddressEntryID = objAddressEntry.ID
strEMailAddress =
objSession.GetAddressEntry(strAddressEntryID).Fiel ds(CdoPR_EMAIL).Value
End If

MsgBox strEMailAddress

My problem is that I can't get this to work with the above code. Are the
message items different in each piece of code? How do you access the
.Sender
property from objInboxEmail?

Thanks for any help.




Ads
 

Bankruptcy - Bankruptcy - Israel - Free Ringtones - Proxy