Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Windows Development  »  Interop  »  Using C# to Create Distribution Lists  »  Creating the Distribution List:
Using C# to Create Distribution Lists
by Muthukumar V | Published  05/10/2005 | Interop | Rating:
Creating the Distribution List:
A distribution list can be created by accessing the Active directory. The object distinguished name of a distribution list will typically look like 

   A Distribution list needs two very basic attributes to be specified at the minimum. One is display name and the second is the alias. A distribution list or a Mailbox can be created only under the Recipients container. 

   To create a distribution list under the Recipients container,

  1. Get the ADSI DirectoryEntry for the Recipients container.
  2. Create a distribution list by specifying "groupOfNames".
  3. Specify the other properties like displaynames, smtp, x400, owner etc.,
  4. Ensure that the Security Descriptor is properly set for the owner attribute.
  5. Commit the changes to the AD.

  The class DirectoryEntry.Children.Add("distributionlistname","groupOfNames") can be used for creating a Distribution List under the recipients container. A call to this function returns an object for the DirectoryEntry for the newly created Distribution List. This does not actually get updated until we call the DirectoryEntry.commitchanges method.

   After getting a pointer to the Distribution list as an object of DirectoryEntry, the following properties are to be updated before calling CommitChanges.

DisplayName Property:

   This is denoted by the cn property name in Exchange. This can be updated by calling the DirectoryEntry.Properties["cn"]. Do call this once before committing the Changes. This ensures that the Display name is updated properly.

Alias Property:

   This is denoted by the uid propertyin Exchange Server. This is the alias name for the distribution list and will typically be used for creating the Object Distinguished name under the container.

Email Addresses Property:

   There could be many types of email addresses in an Exchange environment. They may be smtp, x400, ccmail etc., Set the relevant email addresses. If it is smtp, then mail attribute should be set and for X400 it is textencodedaddress.

   While discussing about the email addresses one point is worth mentioning. The Exchange server keeps all the Email addressing data under a node at SiteAddressing. This data can be pulled from an attribute called GateWay-Proxy, which is not available via ADSI. But it can be pulled using ADO.

Members of Distribution List:

   This is managed under the member property of Exchange. This is an array of list of mailboxes or distribution lists.


   This property is stored under the owner attribute of the Distribution List. There will be a problem when we create the DL and assign an owner. As the DL is freshly created, it won't have any SecurityDescriptor associated with it. To solve this problem, we can pull the SecurityDescriptor of the owner and assign it to the DL.

   The Properties of Exchange 5.5 do not understand the LDAP naming with slashes. It returns an error saying Protocol Error. In such cases, use the comma formatted LDAP Object Distinguished Names. I am not sure about the later versions of Exchange. Be sure to check this out.

   Also some of the properties while setting may return an error saying that the property is not found. In those cases, use the DirectoryEntry.Properties.Add function to add the property. The reason is because, the exchange directory may not keep the property fields if it is not a Required field. In such cases, adding the property will help.

Sponsored Links