Link to home
Start Free TrialLog in
Avatar of pcalabria
pcalabriaFlag for United States of America

asked on

Can I programmatically read an email address from a mail object?

Hello,

I wrote a routine is VB that reads mail that arrives in my MS Outlook 2K Inbox.  I'm able to  loop through the items collection and read the message subject and body, however, I can not read the email address of emails that are received in my Inbox.

For example:

Global objInbox As MAPIFolder

       For n = objInbox.Items.Count To 1 Step -1              
                    Set objMail = objFolder.Items(n)
                    strSubject=objMail.subject
                    strBody=ojbMail.body
                    strSendersEmailAddress=????
'yada yada

       Next

I've done some research and suspect that only the displayname is accessible when Outlook 2K is used.  Can this be correct?  Reading the senders email address seems like it should be a pretty basic thing to do.

Please help!
Avatar of Rgonzo1971
Rgonzo1971

Hi,


Have you tried ?

objMail.SenderEmailAddress

or maybe

objMail.Sender.Address


Regards
How about this:

I have set up an Outlook filter that acts on certain incoming mail (depending on the sender, to be precise - you might set it to react on every message), it gets the message object as attached item. Im the shown code I save the attachmants to a folder after displaying Sender Address and subject in an message box.
Public Sub SaveAttachments(Item As Outlook.MailItem)

    MsgBox (Item.SenderEmailAddress + vbCrLf + Item.Subject)
    
    For Each att In Item.Attachments
    
        att.SaveAsFile ("D:\Temp\" + att.FileName)
    
    Next

End Sub

Open in new window

Avatar of pcalabria

ASKER

Thanks to both of you, however, this does not work.
The problem is that Outlook 2000 does not seem to support the SenderEmailAddress.

From the Immediate window....

?objmail.Subject
Returned mail: see transcript for details

?objmail.SenderName
Mail Delivery Subsystem

?objmail.senderEmailaddress
Returns an Error

?objmail.sender.address
Returns and Error.

We still have Outlook 2000 installed on the workstations because the code we use to send emails will not work with later versions of Outlook.  We will be forced to update at some point, however, for now, we are stuck with Outlook 2K.
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks