I had recently to export the email addresses contained in the BCC: field of an Outlook message. It turned out it’s not that easy. It achieved it with the following of Visual Basic, which will let you pick a folder and dump all recipients for all messages in this folder. I wanted to do it for a specific message and copy the result to the clipboard, but neither of this looks easy in Outlook. I spent already too much time on this so I give up, this version is good enough for me.
Sub ExtractRecipientsFromEmail()
Dim OlApp As Outlook.Application
Dim MailObject As Object
Dim RecipientObject As Object
Dim Email As String
Dim NS As NameSpace
Dim Folder As MAPIFolder
Set OlApp = CreateObject("Outlook.Application")
Set NS = ThisOutlookSession.Session
Set Folder = NS.PickFolder
For Each MailObject In Folder.Items
If MailObject.Class = olMail Then
For Each RecipientObject In MailObject.Recipients
Dim smtp As String
' Debug.Print "ad=", RecipientObject.Address
Select Case RecipientObject.AddressEntry.AddressEntryUserType
Case OlAddressEntryUserType.olExchangeUserAddressEntry
Set oEU = RecipientObject.AddressEntry.GetExchangeUser
If Not (oEU Is Nothing) Then
smtp = oEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olExchangeDistributionListAddressEntry
Set oEDL = RecipientObject.AddressEntry.GetExchangeDistributionList
If Not (oEDL Is Nothing) Then
smtp = oEDL.PrimarySmtpAddress
End If
End Select
Debug.Print smtp
Next
End If
Next
Set OlApp = Nothing
Set MailObject = Nothing
Set RecipientObject = Nothing
End Sub
Filed under: Uncategorized