MailItems - which does i need for the recipients email adress

  • Thread starter Thread starter Mathias Mühlfelder
  • Start date Start date
M

Mathias Mühlfelder

Hy,

i want to know, what mail item i have to use in a vba script do find the
recipients email adress.

look - thats my code:
..........
For Each obj In olFolder.Items
If TypeOf obj Is Outlook.MailItem Then
Set olMail = obj
sAdr = olMail.to
colAdr.Add sAdr, sAdr
End If
Next
..............

sAdr = olMail.to this line brings me up the To Item in the mails. But
sometimes there is no email adresse inside. E. g: "mathias muehlfelder"

i want to become the email adress that have recieved this email object.

can you tell me, what item i have to choose?

i hope you understand my problem...

thanks mathias
 
Use the MailItem.Recipients collection, not To. Each Recipient object has an
Address.
 
Hy Sue,

can you tell me, what is the correct code line?
i can´t find the correct answer. i´ve tried so much, but every time i get a
error message.

Thanxs a lot

Mathias
 
Correct code line for what? The newsgroup interface you are using apparently
does not quote earlier messages in the thread, making your latest message so
short on detail that you risk not getting the answer you're looking form.
Please take the time to quote the original message.
 
Hy Sue,

you write i should use the recipients collection:
This is my code:
..........
For Each obj In olFolder.Items
If TypeOf obj Is Outlook.MailItem Then
Set olMail = obj
sAdr = olMail.to
colAdr.Add sAdr, sAdr
End If
Next
..............

The code line with the "to" MailItem is wrong. I want to get the email
adress on which the mail was sended.
You write i have to use the MailItem Recipient.

Can you tell me the correct code for this: ---sAdr = olMail.to --- line,
that i will get the emailadress insteed of the "to" name?

Thanks

Mathias
 
sAdr = olMail.Recipients(1).Address will get you the first recipient's
address. If you want only To recipients and all of them, you will need to
loop through the Recipients collection and examine the Type of each
Recipient to determine whether it's a To, Cc or Bcc.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top