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 the Item.CC
and Item.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 an Address
property, for every recipient (TO, CC, and BCC).
You could loop through each recipient and concatenate them together. Something like this:
Dim recip As Recipient
Dim allRecips As String
For Each recip In item.Recipients
If (Len(allRecips) > 0) Then allRecips = allRecips & "; "
allRecips = allRecips & recip.Address
Next
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:
- Name - a string value that represents the display name for the recipient.
- Address - a string representing the e-mail address of the Recipient.
- AddressEntry - the AddressEntry object corresponding to the recipient.