Get email recipients (FROM / TO / CC / BCC) from outlook mail item

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
My code I have creates a table from getTable method but I have recently learned there is no MAPI property to return the email addresses of these so my table columns are useless for this part. It seems the only way to do it is via the mail item object. However, I notice with my code below which uses another persons code on stackoverflow this returns a lot more information then just the email addresses. I am also not sure why this code checks to see if its an exchange user as well and this code only address recipients and actually is pretty slow.

Code:
        For Each OutRecip In Session.GetItemFromID(nextRow("EntryID")).Recipients
            'Debug.Print nextRow("Subject") & OutRecip.Address
            Select Case OutRecip.AddressEntry.AddressEntryUserType
                Case 0, 10
                    Set objExUser = OutRecip.AddressEntry.GetExchangeUser
                    If Not objExUser Is Nothing Then _
                    Debug.Print OutRecip.Address & objExUser.PrimarySmtpAddress '/* or copy somewhere */
                Case 1
                    Set objExDisUser = OutRecip.AddressEntry.GetExchangeDistributionList
                    If Not objExDisUser Is Nothing Then _
                    Debug.Print  objExDisUser.PrimarySmtpAddress  '/* or copy somewhere */
                Case Else
                '/* Do nothing, recipient not recognized */
                End Select
        Next
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I still dont understand why they use that exchange object but I have shortened it up a bit and get a cleaner version for the recipient email addresses. I do wonder if there is a faster way to pull the email addresses from the advance search. Is there no field in the namespace schemas which have these properties which can extract those email addresses?

Code:
    Do Until MyTable.EndOfTable
        Set nextRow = MyTable.GetNextRow()
        For Each OutRecip In Session.GetItemFromID(nextRow("EntryID")).Recipients
            OutRecip.PropertyAccessor.GetProperty ("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")
        Next
    Loop
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top