Problem with getting actual email address.

  • Thread starter Thread starter Bob Leffew
  • Start date Start date
B

Bob Leffew

I have successfully been able to read my "Sent" messages to write out to an
Access database.

Problem is I want to be able to extract specific email addresses instead of
having to read the whole data base.

The problem I am having is that in my statement (as shown below in my code)

If LCase$(thismessage.To) <> LCase(txtEmailAddress.text) Then GoTo
NotAMatch

thismessage.To is not always the actual email address. What I seem to have
figured out is there is a way to get to the actual email address by using
oRecip. But I cant seem to figure it out. Can someone point me in the
right direction.

I understand you need to Set ORecip and Dim it but not sure how.

Thanks,

Bob Leffew



Set OLApp = CreateObject("Outlook.Application.11")
Set OLFolders = OLApp.GetNamespace("Mapi")
Set OLSentItems =
OLFolders.GetDefaultFolder(olFolderSentMail).Items


Set rsEmail = New ADODB.Recordset
rsEmail.CursorLocation = adUseClient
rsEmail.MaxRecords = 1
rsEmail.Open "Select * From EmailsBobSent",
modMakeConnectionSGI.cnSGI, adOpenDynamic, adLockOptimistic

PopGridSent:

countrecords = 0

For Each thismessage In OLSentItems

sAdr = LCase$(txtEmail1.Text)
If LCase$(thismessage.To) <> LCase(txtEmailAddress.text)
Then GoTo NotAMatch
rsEmail.AddNew
rsEmail!EmailSentTo = CStr(thismessage.To)
rsEmail!EmailSentOn = thismessage.SentOn
rsEmail!EmailSubject = thismessage.Subject
rsEmail!EmailBody = thismessage.Body
rsEmail.Update
NotAMatchSent:
Next
EndThisSubsent:
rsEmail.Requery
 
I am assuming since no one is answering that this problem is unsolvable.

If so any suggestions?



Bob Leffew
 
Maybe next time you'll be willing to wait more than 49 minutes for an answer?

The actual email address is not in the To property but in each Recipient.Address property from the Recipients collection:

For Each recip in thismessage.Recipients
strAddress = recip.Address
' <your code to do whatever youi want to do with the address>
Next

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I am sorry, I did not mean anything bad from it.

I tried what you said but i keep getting error message "object doesnt
support this property or method".

This is the line it errors on and then below is the complete code.

For Each oRecip In OLSentItems.Recipients

Thanks for your help, greatly appreciated.

Bob Leffew

Set OLApp = CreateObject("Outlook.Application.11")
Set OLFolders = OLApp.GetNamespace("Mapi")
Set OLSentItems =
OLFolders.GetDefaultFolder(olFolderSentMail).Items

Dim oRecip As Outlook.Recipient


For Each thismessage In OLSentItems

sAdr = LCase$(txtEMail1.Text)

For Each oRecip In OLSentItems.Recipients
If LCase$(oRecip.Address) = sAdr Then
EmailHold = oRecip.Address
NameHold = oRecip.Name
End If
Next

If LCase$(EmailHold) Or LCase$(NameHold) = sAdr Then
GoTo NotAMatchSent
Else
rsEmail.AddNew
rsEmail!EmailSentTo = CStr(thismessage.To)
rsEmail!EmailSentOn = thismessage.SentOn
rsEmail!EmailSubject = thismessage.Subject
rsEmail!EmailBody = thismessage.Body
rsEmail.Update
End If
NotAMatchSent:
Next



Maybe next time you'll be willing to wait more than 49 minutes for an
answer?

The actual email address is not in the To property but in each
Recipient.Address property from the Recipients collection:

For Each recip in thismessage.Recipients
strAddress = recip.Address
' <your code to do whatever youi want to do with the address>
Next

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Why didn't you use the code I provided? Recipients is a property of the MailItem object.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thanks for your help. Worked great.

What confused me about your code you gave me was that I thought it wasnt
complete since you put:

For Each recip in thismessage.Recipients
strAddress = recip.Address
' <your code to do whatever youi want to do with the address>
Next

I thought you were just giving me general code becouse you had recip where I
had oRecip. I then figured it out that you just did not put down what I
had. Guess I am not as smart as you.

But I am going to buy your book. Will you autograph it for me?

Thanks,

Bob Leffew


Why didn't you use the code I provided? Recipients is a property of the
MailItem object.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Actually I did make an effort to put down what you had -- using the thismessage variable that was in your original code.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top