Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / November 2006

Tip: Looking for answers? Try searching our database.

determining Senders smtp address

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Young - 01 Nov 2006 00:33 GMT
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).Fields(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.
Ken Slovak - [MVP - Outlook] - 01 Nov 2006 14:58 GMT
Why not just use PR_SENDER_EMAIL_ADDRESS (&HC1F001E) in the Fields
collection of the Message item?

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

>I am trying to obtain the smtp address of a message selected by our
> Servicedesk staff using the code:
[quoted text clipped - 40 lines]
>
> Thanks for any help.
Dmitry Streblechenko - 01 Nov 2006 19:13 GMT
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

>I am trying to obtain the smtp address of a message selected by our
> Servicedesk staff using the code:
[quoted text clipped - 40 lines]
>
> Thanks for any help.
Paul Young - 02 Nov 2006 04:29 GMT
Thanks for your help.

I've used your suggestions and the following code does now work:

Const PR_EMS_AB_PROXY_ADDRESSES = &H800F101E

Set objOutlook = CreateObject("Outlook.Application")
Set objActiveExplorer = objOutlook.ActiveExplorer
Set objInboxEmail = objActiveExplorer.Selection(1)
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", True, False, 0

strEntryID = objInboxEmail.EntryID
strStoreID = objInboxEmail.Parent.StoreID
Set objCDOMessage = objSession.GetMessage(strEntryID, strStoreID)
Set objAddEntry = objCDOMessage.Sender
If objAddEntry.Type = "EX" Then
    Set objField = objAddEntry.Fields(PR_EMS_AB_PROXY_ADDRESSES)
    For Each strEmailAddress In objField.Value
           If Left(strEmailAddress, 5) = "SMTP:" Then
                   strAddress = Mid(strEmailAddress, 6)
                   MsgBox strAddress
                   Exit For
                    End If
    Next
End If

Problem now is the Outlook security message comes up each time regardless of
the Allow Access for time selected.  I know it is normal for it to come up
but normally you can select a time to allow this.  Is this a function of the
objSession.Logon?  Is there parameters to change this behaviour?

Redemption does seem easier however I would have to roll it out to a few
users first.

Thanks for your help.

Paul

> The messages are different because you are assuming that the item you are
> processing is the last in the folder (objMessages.GetLast). Firstly, the
[quoted text clipped - 71 lines]
> >
> > Thanks for any help.
Dmitry Streblechenko - 02 Nov 2006 18:18 GMT
CDO 1.21 implements is own "Allow Access" dialog, so even if you dismiss the
OOM's dialog, CDO will still show its own one.
You can optimize your code a bit (or a lot) if you only intend to run it in
Outlook 2002 and up: Replace the line
objSession.Logon "", "", True, False, 0
with
objSession.MAPIOBJECT = objOutlook.Session.MAPIOBJECT

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

> Thanks for your help.
>
[quoted text clipped - 117 lines]
>> >
>> > Thanks for any help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.