Problem with Sent Items/Redemption

G

Guest

Hi!

I am using the Redemption library to find the SenderEmailAddress of a mail.
It works fine in Inbox, but I want something else:
for an item in Sent Items I wand the "To" property to give me an email
address, but I am getting only a name. How do I get the proprty "To", like I
get SenderEmailAddress in Inbox?

Thanks,
Yonina.
 
K

Ken Slovak - [MVP - Outlook]

PR_DISPLAY_TO (0x0E04001E) is a name field. To get the actual email address
you would need to access the Recipients collection of the email item and use
the PR_EMAIL_ADDRESS (0x3003001E) field.
 
G

Guest

How would I do that?
I tried code from outlookcode, but it didn't help.
Maybe you can give me a code sample or a site that has a code sample?

here is what I tried:

Dim folderName As String
folderName = Application.ActiveExplorer.CurrentFolder

Set ol = GetObject(, "OUTLOOK.APPLICATION")
Set MAPI = ol.GetNamespace("MAPI")

Set rmafolder = MAPI.folders("Mailbox - Ayelet")

If folderName = "Inbox" Then
Set Folder = rmafolder.folders("Inbox")
act = "In"
Else
If folderName = "Sent Items" Then
Set Folder = rmafolder.folders("Sent Items")
act = "Out"
Else
GoTo Err
End If
End If


For Each mail In Folder.Items
If mail.Body = strEmail Then
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False

' pass message to CDO
strEntryID = mail.EntryID
strStoreID = mail.Parent.StoreID
Set objCDOMsg = objSession.GetMessage(strEntryID,
strStoreID)
If act = "In" Then
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False

' pass message to CDO
strEntryID = mail.EntryID
strStoreID = mail.Parent.StoreID
Set objCDOMsg = objSession.GetMessage(strEntryID,
strStoreID)

' get sender address
On Error Resume Next
strAddress = objCDOMsg.Sender.Address
If Err = &H80070005 Then
'handle possible security patch error
MsgBox "The Outlook E-mail and CDO Security Patches
are " & _
"apparently installed on this machine. " & _
"You must response Yes to the prompt about " & _
"accessing e-mail addresses if you want to " & _
"get the From address.", vbExclamation, _
"GetFromAddress"
End If

GetFromAddress = strAddress

Set objCDOMsg = Nothing
objSession.Logoff
Set objSession = Nothing
MsgBox (mail.SenderEmailAddress)
adrs = mail.SenderEmailAddress
GoTo aaa
Else
If act = "Out" Then
Set objReply = objCDOMsg.Reply
On Error Resume Next
Set objRecip = objReply.Recipients.Item(1)
strAddress = objRecip.Address
If strAddress = "" Then
strAddress = objRecip.Name
End If
ElseIf Err = 287 Then
'handle possible security patch error
strAddress = ""
MsgBox "The Outlook E-mail Security Patch is " & _
"apparently installed on this machine. " & _
"You must response Yes to the prompt about " & _
"accessing e-mail addresses if you want to " & _
"get the Reply To address.", vbExclamation, _
"GetReplyToAddress"
End If

GetReplyToAddress = strAddress
MsgBox strAddress

Set objRecip = Nothing
Set objReply = Nothing

GoTo aaa
End If
End If
'how to get actual email address
End If
Next
 
D

Dmitry Streblechenko

Loop through all the items in the Recipients collection and for each
recipient check that the Type property = olTo. If true, read the
Recipient.Address property.

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

Guest

hi,

this is the code I tried:
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.Application.ActiveExplorer.Selection(1)
Set myrecipient = myItem.Recipients.Address
MsgBox myrecipient

and this is the error I get:
error number: 438
description: Object doesn't support this property or method

please! I need help!
 
K

Ken Slovak - [MVP - Outlook]

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.Application.ActiveExplorer.Selection(1)
MyRecipientAddress = myItem.Recipients(1).Address
MsgBox MyRecipientAddress

or to show every recipient:

For Each oRecipient in myItem.Recipients
MsgBox oRecipient.Address
Next
 
G

Guest

THANK YOU!!!

EXACTLY WHAT I NEEDED!!!

:)

Ken Slovak - said:
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.Application.ActiveExplorer.Selection(1)
MyRecipientAddress = myItem.Recipients(1).Address
MsgBox MyRecipientAddress

or to show every recipient:

For Each oRecipient in myItem.Recipients
MsgBox oRecipient.Address
Next
 
G

Guest

Is there any way to avoid the message:
A program is trying to access e-mail addresses you have stored in Outlook.
Do you want to allow this?
 
K

Ken Slovak - [MVP - Outlook]

Yes, use Redemption. Read access to the email addresses is restricted as an
email address harvesting precaution. If you use Redemption objects for the
Recipient objects you won't get the security prompts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top