A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

determining Senders smtp address



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 1st 06, 12:33 AM posted to microsoft.public.outlook.program_vba
Paul Young
external usenet poster
 
Posts: 3
Default determining Senders smtp address

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
  #2  
Old November 1st 06, 02:58 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default determining Senders smtp address

Why not just use PR_SENDER_EMAIL_ADDRESS (&HC1F001E) in the Fields
collection of the Message item?

--
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


"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.



  #3  
Old November 1st 06, 07:13 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
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.




  #4  
Old November 2nd 06, 04:29 AM posted to microsoft.public.outlook.program_vba
Paul Young
external usenet poster
 
Posts: 3
Default determining Senders smtp address

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

"Dmitry Streblechenko" wrote:

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.





  #5  
Old November 2nd 06, 06:18 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default determining Senders smtp address

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

"Paul Young" wrote in message
...
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

"Dmitry Streblechenko" wrote:

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.







 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ÎÞ·¨ÕÒµ½Ö÷»ú¡°SMTP¡±¡£Çë¼ì²éÊäÈëµÄ·þÎñÆ÷ÃûÊÇ·ñÕýÈ·¡£ ÕÊ»§: 'POP3', ·þÎñÆ÷: 'SMTP', ЭÒé: SMTP, ¶Ë¿Ú: 25, °²È«(SSL): ·ñ, Ì×½Ó×Ö´íÎó: 11001, ´íÎóºÅ: 0x800CCC0D John Smith Outlook Express 0 September 5th 06 02:15 AM
SMTP Rejected email address FyrFtrEmt Outlook Express 4 June 19th 06 12:10 AM
ÎÞ·¨ÕÒµ½Ö÷»ú¡°smtp¡±¡£Çë¼ì²éÊäÈëµÄ·þÎñÆ÷ÃûÊÇ·ñÕýÈ·¡£ ÕÊ»§: 'pop3', ·þÎñÆ÷: 'smtp', ЭÒé: SMTP, ¶Ë¿Ú: 25, °²È«(SSL): ·ñ, Ì×½Ó×Ö´íÎó: 11001, ´íÎóºÅ: 0x800CCC0D Outlook Express 0 June 17th 06 10:44 AM
How to determine what SMTP address email was sent to? BCole8888 Outlook - General Queries 3 February 8th 06 04:08 PM
Determining account being used Scott Outlook and VBA 2 January 25th 06 05:39 PM


All times are GMT +1. The time now is 12:57 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.