james henderson
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.
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);
}
}
}
}
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\Micros oft.Office .Interop.O utlook.dll
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\Micros
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect! Is there a way to do this against Active Directory without having to use the interop dll?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.