tags:

views:

1253

answers:

2

I need to send an email to an Exchange distribution list called "DL-IT" using c#.

Does anyone know how to achieve this?

+2  A: 

The simplest way would be to find the actual email address of the DL, and use that in your "To:" field. Exchange distribution lists actually have their own email addresses, so this should work fine.

Harper Shelby
+2  A: 

Exchange server runs SMTP so one can use the SmtpClient to send an email.

One can lookup the SMTP address of the distribution list (manually) and use that as the "to" address on the MailMessage constructor. The constructor call will fail if you just pass in the name of the distribution list as it doesn't look like a real email address.

public void Send(string server, string from, string to)
{
    // Client to Exchange server
    SmtpClient client = new SmtpClient(server);

    // Message
    MailMessage message = new MailMessage(from, to);
    message.Body = "This is a test e-mail message sent by an application. ";
    message.Subject = "test message 1";

    // Credentials are necessary if the server requires the client 
    // to authenticate before it will send e-mail on the client's behalf.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    // Send
    client.Send(message);
}
Scott Saad
Will Exchange actually do a lookup like that on a DL name sent via SMTP? I was under the impression that it didn't.
Harper Shelby
You're absolutely right. Sorry... answer has been updated.
Scott Saad