问题
I need to send an email to an Exchange distribution list called "DL-IT" using c#.
Does anyone know how to achieve this?
回答1:
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.
回答2:
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);
}
回答3:
Basically you need to combine two solutions above.
Using code snippet from Scott solution - you should send to DL-IT@mycompany.com
.
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
.
回答4:
The above answers are fine, just be aware that if one of the members of the of the distribution list is not a valid address, the SMTP server may reject the entire Email message as being undeliverable.
This may be because in our case we are using an SMTP server that is not part of Exchange, but never the less it's something to be aware of.
回答5:
In my case it wasn't working because I sent the email to one of multiple aliases that were defined for this list. It seems to me like the address that is used for display may be different than the real address.
The way I got it to work was in Outlook (2016) to click on the "To..." button, then in the global address book search for the ML. There were two entries, one with a globe symbol, one with a people symbol.
Right click the one with the globe, select Properties. Here you can find the email address.
来源:https://stackoverflow.com/questions/916170/how-do-i-send-an-email-to-an-exchange-distribution-list-using-c-sharp