How do I send an email to an Exchange Distribution list using c#
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.
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);
}
Basically you need to combine two solutions above.
Using code snippet from Scott solution - you should send to [email protected]
.
But exchange name alias is not always the same as group e-mail, so
- you may open an empty e-mail in Outlook with
DL-IT
inTo
field - double-click the
DL-IT
inTo
field - copy value from
Alias Name
field and add@mycompany.com
.