I need to get the recipient email address out of an item on Outlook 2010.
My code is as follow:
sSQL = "SELECT id from dbo.database where email_address LIKE '" & Item.RecipientEmailAddress & "'
item.recipientEmailAddress is not valid, but I need something like that.
I know that you have a code call Item.SenderEmailAddress but in this case I need the recipient's email address.
I've seen some other threads on that subject but I did not manage to make any of them work.
For a "quick" way of doing it, you can concatenate the
Item.To
together with theItem.CC
andItem.BCC
properties, however, this may not be what you're looking for as sometimes these properties store the display names instead of the SMTP email addresses.Another way is to use the
Item.Recipients
collection which contains a Recipient object, which contains anAddress
property, for every recipient (TO, CC, and BCC).You could loop through each recipient and concatenate them together. Something like this:
The Recipients property of the MailItem class returns a Recipients collection that represents all the recipients for the Outlook item.
The Type property of the Recipient class returns or sets an integer representing the type of recipient. For the MailItem the value can be one of the following OlMailRecipientType constants: olBCC, olCC, olOriginator, or olTo.
Also the Recipient class provides the following properties: