Link to home
Start Free TrialLog in
Avatar of james henderson
james hendersonFlag for United States of America

asked on

get distribution list from gal

I am using c# in vs 2008.  I have a small class to handle sending smtp email to our Exchange server 2003 to send email to a selected distribution list, but have no idea how to get the list of distribution list email addresses.  Any help greatly appreciated.
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

If I correctly understood your problem, a distribution list is the same as any other e-mail address. So you can use the same class which you are using it for individual emails.
or do you mean this?

using Outlook = Microsoft.Office.Interop.Outlook;

private void GetDistributionListMembers()
{
	Outlook.SelectNamesDialog snd =
		Application.Session.GetSelectNamesDialog();
	Outlook.AddressLists addrLists =
		Application.Session.AddressLists;
	foreach (Outlook.AddressList addrList in addrLists)
	{
		if (addrList.Name == "All Groups")
		{
			snd.InitialAddressList = addrList;
			break;
		}
	}
	snd.NumberOfRecipientSelectors =
		Outlook.OlRecipientSelectors.olShowTo;
	snd.ToLabel = "D/L";
	snd.ShowOnlyInitialAddressList = true;
	snd.AllowMultipleSelection = false;
	snd.Display();
	if (snd.Recipients.Count > 0)
	{
		Outlook.AddressEntry addrEntry =
			snd.Recipients[1].AddressEntry;
		if (addrEntry.AddressEntryUserType ==
			Outlook.OlAddressEntryUserType.
			olExchangeDistributionListAddressEntry)
		{
			Outlook.ExchangeDistributionList exchDL =
				addrEntry.GetExchangeDistributionList();
			Outlook.AddressEntries addrEntries =
				exchDL.GetExchangeDistributionListMembers();
			if (addrEntries != null)
				foreach (Outlook.AddressEntry exchDLMember
								in addrEntries)
				{
					Debug.WriteLine(exchDLMember.Name);
				}
		}
	}
}

Open in new window

Avatar of james henderson

ASKER

Thanks for your reply.

I was hoping to stay away from the outlook intrerop stuff as we have multiple versions of outlook but...

I tried using your code example and receive the compile error:
"  The name 'Application' does not exist in the current context  "

I have added the following .net reference:
C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Outlook.dll
ASKER CERTIFIED SOLUTION
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perfect!  Is there a way to do this against Active Directory without having to use the interop dll?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial