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.
dhenderson12Asked:
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.
0
Roshan DavisCommented:
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

0
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
0
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"]; 
listBox1.Items.Add(oGal.Name); 

// 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]; 

listBox1.Items.Add(oDL.Name); 
listBox1.Items.Add(oDL.Address); 
if(oDL.Manager != null) 
listBox1.Items.Add(oDL.Manager); 

// 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]; 
    listBox1.Items.Add(oEntry.Name); 
} 

// Display the Details dialog box. 
//oDL.Details(Missing.Value) 

// Log off. 
oNS.Logoff(); 

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

Open in new window

0

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?
0
Roshan DavisCommented:
I need to check
btw, will this thread help?
http://www.experts-exchange.com/Database/LDAP/Q_24135043.html
0
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
C#

From novice to tech pro — start learning today.