Solved

Reading the sender of an email's address

Posted on 2000-02-29
6
235 Views
Last Modified: 2010-05-18
I've written an office automation program that reads each message from Outlook 98 and filters them as necessary. It is finished except for one minor part. I cannot get the sender's email address 100% of the time, only about 80%.

I have looked through the entire message object on a email that doesn't give me its address (I can get the sender's name, but not the address).

Part of the code (relevant bits) is below, aswell as the statements I currently use to get the address (on the ones which have them).

-------------------------------

    Set dbMail = DBEngine(0).OpenDatabase("export.mdb")
   
    For Each msgOutlook In folderOutlook.Items
               
        If (msgOutlook.ReplyRecipientNames = "") Then
            strFROM = msgOutlook.SenderName
        Else
            strFROM = msgOutlook.ReplyRecipientNames
        End If

        'Rest of code

-------------------------------

'msgOutlook.ReplyRecipientNames' sometimes contain the address, otherwise I have to use 'msgOutlook.SenderName' which contains the name of the sender.

Anything I have missed that will get me the email address 100% of the time?


0
Comment
Question by:AdamWoodland
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:cquinn
ID: 2569665
I believe the way to do it is to create a reply (which you later destroy without sending it) and look at the address property of the reply object.
0
 
LVL 15

Accepted Solution

by:
cquinn earned 100 total points
ID: 2569869
I have investigated further, and the way I do it using CDO is to look at the .sender.address property.

Using the outlook object model, you would need to look at message.recipients(0).address property of the temporary reply object - something like

oReply=msgOutlook.reply
strfrom =oReply.Recipients(0).Address
0
 
LVL 2

Author Comment

by:AdamWoodland
ID: 2569903
Cheers, I'll give that reply a go tomorrow.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:AdamWoodland
ID: 2571850
That seems to work for the messages that I couldn't get the address from (only the name), I used that in conjunction with my other code and between them it works 100% (so far, but I have to do some more testing).

Thanks again cquinn.

Adam
0
 
LVL 2

Author Comment

by:AdamWoodland
ID: 2571860
Oh yes - forgot to mention, your code should have been (in my case):

Set oReply = msgOutlook.Reply
strFROM = oReply.Recipients.Item(1).Address

:-)

Your suggestion helped, I only had to do a bit of tweaking.
0
 
LVL 2

Author Comment

by:AdamWoodland
ID: 2571867
That seems to work for the messages that I couldn't get the address from (only the name), I used that in conjunction with my other code and between them it works 100% (so far, but I have to do some more testing).

Thanks again cquinn.

Adam
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now