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 
LDAP://ExchangeServerName/o=OrgName/ou=SiteName/cn=Recipients/cn=alias-name

   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.

Owner:

   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.

Comments    Submit Comment

Comment #1  (Posted by an unknown user on 10/07/2005)
Rating
good
 
Comment #2  (Posted by David Smith on 09/15/2006)
Rating
As it came, it didn't work. I added a reference to Interop.MAPI, the added 'using MAPI;', at which point it built successfully - but when run, nothing happened. When I checked, there was no startup object, so I selected the form. Same result - nothing came up.

So, my question is - did you EVER run this yourself?
 
Comment #3  (Posted by an unknown user on 09/15/2006)
Rating
There is a fairly detailed explaination, but the example didn't work
 
Comment #4  (Posted by an unknown user on 09/15/2006)
Rating
Excellent work. Thanks.
 
Comment #5  (Posted by an unknown user on 09/29/2006)
Rating
Sounds very interesting...but I can't get it to work. I get an error beginning with..."System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational at...[etc]"

Does anyone know what is needed to make it work?
 
Comment #6  (Posted by an unknown user on 10/02/2006)
Rating
Good One. Concepts are explained very well.
 
Comment #7  (Posted by David on 10/17/2006)
Rating
Nice conceptual level explanation. ought to check the sample.
 
Comment #8  (Posted by Ian Dunn on 07/12/2007)
Rating
After jumping through some hoops to try to get it to compile, I get this exception when trying to do gSession.Logon:

System.Runtime.InteropServices.COMException (0x80040111): [Collaboration Data Objects - [MAPI_E_LOGON_FAILED(80040111)]]

Are there some specific security settings needed for anonymous logon?
 
Comment #9  (Posted by an unknown user on 03/28/2008)
Rating
Can you add another method that will retreive all distribution list name from exhanger server. Adding and removing user to the distribution list.
 
Sponsored Links