I need to send an email to an Exchange distribution list called "DL-IT" using c#.
我需要使用c#向名为“DL-IT”的Exchange通讯组列表发送电子邮件。
Does anyone know how to achieve this?
有谁知道如何实现这一目标?
4 个解决方案
#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.
最简单的方法是找到DL的实际电子邮件地址,并在“收件人:”字段中使用它。 Exchange分发列表实际上有自己的电子邮件地址,因此这应该可以正常工作。
#2
Exchange server runs SMTP so one can use the SmtpClient to send an email.
Exchange服务器运行SMTP,因此可以使用SmtpClient发送电子邮件。
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.
可以查找通讯组列表的SMTP地址(手动),并将其用作MailMessage构造函数上的“to”地址。如果您只是传递分发列表的名称,构造函数调用将失败,因为它看起来不像真正的电子邮件地址。
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
.
使用Scott解决方案的代码片段 - 您应该发送到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
.
您可以在Outlook中使用DL-IT在“收件人”字段中打开一个空电子邮件
双击“收件人”字段中的DL-IT
从Alias Name字段复制值并添加@ 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.
上述答案很好,请注意,如果通讯组列表中的某个成员不是有效地址,则SMTP服务器可能会拒绝整个电子邮件消息,因为它们无法传送。
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.
这可能是因为在我们的情况下,我们使用的是不属于Exchange的SMTP服务器,但从来没有人能够意识到这一点。
#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.
最简单的方法是找到DL的实际电子邮件地址,并在“收件人:”字段中使用它。 Exchange分发列表实际上有自己的电子邮件地址,因此这应该可以正常工作。
#2
Exchange server runs SMTP so one can use the SmtpClient to send an email.
Exchange服务器运行SMTP,因此可以使用SmtpClient发送电子邮件。
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.
可以查找通讯组列表的SMTP地址(手动),并将其用作MailMessage构造函数上的“to”地址。如果您只是传递分发列表的名称,构造函数调用将失败,因为它看起来不像真正的电子邮件地址。
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
.
使用Scott解决方案的代码片段 - 您应该发送到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
.
您可以在Outlook中使用DL-IT在“收件人”字段中打开一个空电子邮件
双击“收件人”字段中的DL-IT
从Alias Name字段复制值并添加@ 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.
上述答案很好,请注意,如果通讯组列表中的某个成员不是有效地址,则SMTP服务器可能会拒绝整个电子邮件消息,因为它们无法传送。
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.
这可能是因为在我们的情况下,我们使用的是不属于Exchange的SMTP服务器,但从来没有人能够意识到这一点。