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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roshan DavisCommented:
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.
Roshan DavisCommented:
or do you mean this?

using Outlook = Microsoft.Office.Interop.Outlook;

private void GetDistributionListMembers()
	Outlook.SelectNamesDialog snd =
	Outlook.AddressLists addrLists =
	foreach (Outlook.AddressList addrList in addrLists)
		if (addrList.Name == "All Groups")
			snd.InitialAddressList = addrList;
	snd.NumberOfRecipientSelectors =
	snd.ToLabel = "D/L";
	snd.ShowOnlyInitialAddressList = true;
	snd.AllowMultipleSelection = false;
	if (snd.Recipients.Count > 0)
		Outlook.AddressEntry addrEntry =
		if (addrEntry.AddressEntryUserType ==
			Outlook.ExchangeDistributionList exchDL =
			Outlook.AddressEntries addrEntries =
			if (addrEntries != null)
				foreach (Outlook.AddressEntry exchDLMember
								in addrEntries)

Open in new window

dhenderson12Author Commented:
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Roshan DavisCommented:
can you try this instead, I think I've given the C# ASP.NET part
// Create Outlook application. 
Outlook.Application oApp = new Outlook.Application(); 

// Get Mapi NameSpace and Logon. 
Outlook.NameSpace oNS = oApp.GetNamespace("mapi"); 
oNS.Logon(Missing.Value, Missing.Value, false, true); 
// TODO: 

// Get Global Address List. 
Outlook.AddressLists oDLs = oNS.AddressLists; 
Outlook.AddressList oGal = oDLs["Global Address List"]; 

// Get a specific distribution list. 
// TODO: Replace the distribution list with a distribution list that is available to you. 
string sDL = "TestDL"; 
Outlook.AddressEntries oEntries = oGal.AddressEntries; 
// No filter available to AddressEntries 
Outlook.AddressEntry oDL = oEntries[sDL]; 

if(oDL.Manager != null) 

// Get all of the members of the distribution list. 
oEntries = oDL.Members; 
Outlook.AddressEntry oEntry = default(Outlook.AddressEntry); 
int i = 0; 

for (i = 1; i <= oGal.AddressEntries.Count && i <= 300; i++) 
    oEntry = oGal.AddressEntries[i]; 

// Display the Details dialog box. 

// Log off. 

// Clean up. 
oApp = null; 
oNS = null; 
oDLs = null; 
oGal = null; 
oEntries = null; 
oEntry = null; 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dhenderson12Author Commented:
perfect!  Is there a way to do this against Active Directory without having to use the interop dll?
Roshan DavisCommented:
I need to check
btw, will this thread help?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.