Is it possible, or how would one go about, finding all the public distribution lists an email address is on?
For example,
john.does@mail.com
is on the following distribution lists:
list1
list2
list3
etc…
Thanks in advance - J
Is it possible, or how would one go about, finding all the public distribution lists an email address is on?
For example,
john.does@mail.com
is on the following distribution lists:
list1
list2
list3
etc…
Thanks in advance - J
You may please use following sample code to identify lists which contain specific email address. Please give it a try and share the feedback.
MapiDistributionListMemberCollection oneOffmembers = new MapiDistributionListMemberCollection();
oneOffmembers.Add(new MapiDistributionListMember("John R. Patrick 1", "JohnRPatrick1@gmail.com"));
oneOffmembers.Add(new MapiDistributionListMember("Tilly Bates 1", "TillyBates1@gmail.com"));
MapiDistributionList oneOffMembersList = new MapiDistributionList("Simple list 1", oneOffmembers);
MapiDistributionListMemberCollection twoOffmembers = new MapiDistributionListMemberCollection();
twoOffmembers.Add(new MapiDistributionListMember("John R. Patrick 2", "JohnRPatrick2@gmail.com"));
twoOffmembers.Add(new MapiDistributionListMember("Tilly Bates 2", "TillyBates2@gmail.com"));
MapiDistributionList twoOffMembersList = new MapiDistributionList("Simple list 2", twoOffmembers);
MapiDistributionListMemberCollection threeOffmembers = new MapiDistributionListMemberCollection();
threeOffmembers.Add(new MapiDistributionListMember("John R. Patrick 3", "JohnRPatrick3@gmail.com"));
threeOffmembers.Add(new MapiDistributionListMember("Tilly Bates 3", "TillyBates1@gmail.com"));
MapiDistributionList threeOffMembersList = new MapiDistributionList("Simple list 3", threeOffmembers);
var distributionsLists = new List<MapiDistributionList>();
distributionsLists.Add(oneOffMembersList);
distributionsLists.Add(twoOffMembersList);
distributionsLists.Add(threeOffMembersList);
string TargetEmail = "TillyBates1@gmail.com";
List<string> FilteredLists = new List<string>();
foreach(MapiDistributionList list in distributionsLists)
if(list.Members.Any(member => member.EmailAddress == TargetEmail))
FilteredLists.Add(list.DisplayName);
For more details on distribution lists, please visit here.