Check if an address is in the recipient list including distribution lists?

  • Thread starter Thread starter PilotYid
  • Start date Start date
P

PilotYid

Basically, In my Application_ItemSend I would like to check if a
particular person or persons are in the recipient list (To or CC). I
tried this by looping through mailItem.Recipients and checking each
one. Problem is that this won't look inside of distribution lists, so
if I send to a distribution list that has this person in it, this won't
detect it. How can I do this? Any way to expand the dist. list at this
point to look inside, and/or determine if a particular recipient is a
dist list?

Thanks for your help,
Aaron
 
Thanks. When I am looping through the recepients on the email, how do I
know if it is a DL so I can know to check the Members collection? Or do
all recepients have a Members collection, but are just size 1 for
regular addresses? Would you mind giving me a small code sample?

Thanks again
 
For the DLs the Members property is non-NULL.
Or chekc that the AddressEntry.DisplayType property is set to olDistList or
olPrivateDistList.

sub ProcessAddressEntry(AddressEntry)
if (AddressEntry = olDistList) or (AddressEntry = olPrivateDistList)
Then
for i = 1 to AddressEntry.Members.Count
ProcessAddressEntry AddressEntry.Members(i)
next
Else
Debug.Print AddressEntry.Address
End If
end sub
....
for i = 1 to MailItem.Recipients.Count
set AddressEntry = MailItem.Recipients(i).AddressEntry
if not (AddressEntry Is Nothing) Then
ProcessAddressEntry(AddressEntry)
End If
next

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks for your help. For some reason, the distribution lists in my
company are showing up as displaytype 0, not DistList or
PrivateDistList. Do you have any ideas why this would be? Is there
another way to do this?
Thanks again
 
Are you sure? 0 is olUser. Are you using Exchange? Did you try to test if
the Members collection is non NULL?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top