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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Roshan DavisConnect With a Mentor Commented:
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
 
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
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
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
 
dhenderson12Author Commented:
perfect!  Is there a way to do this against Active Directory without having to use the interop dll?
0
 
Roshan DavisConnect With a Mentor Commented:
I need to check
btw, will this thread help?
http://www.experts-exchange.com/Database/LDAP/Q_24135043.html
0
All Courses

From novice to tech pro — start learning today.