如何使用 c# 向 Exchange 分发列表发送电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/916170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:08:12  来源:igfitidea点击:

How do I send an email to an Exchange Distribution list using c#

c#emailexchange-server

提问by Calanus

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?

有谁知道如何实现这一目标?

采纳答案by Harper Shelby

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 通讯组列表实际上有自己的电子邮件地址,所以这应该可以正常工作。

回答by Scott Saad

Exchange server runs SMTP so one can use the SmtpClientto 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 MailMessageconstructor. The constructor call will fail if you just pass in the name of the distribution list as it doesn't looklike a realemail address.

可以(手动)查找通讯组列表的 SMTP 地址,并将其用作MailMessage构造函数上的“收件人”地址。如果您只是传入分发列表的名称,则构造函数调用将失败,因为它看起来不像真正的电子邮件地址。

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);
}

回答by Alex Pinsker

Basically you need to combine two solutions above.

基本上你需要结合上面的两个解决方案。

Using code snippet from Scott solution - you should send to [email protected].

使用 Scott 解决方案中的代码片段 - 您应该发送到[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-ITin Tofield
  • double-click the DL-ITin Tofield
  • copy value from Alias Namefield and add @mycompany.com.
  • 您可以在 Outlook 中使用DL-ITinTo字段打开一封空电子邮件
  • 双击DL-IT输入To字段
  • Alias Name字段复制值并添加@mycompany.com.

回答by Jose Lizar

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.

这可能是因为在我们的案例中,我们使用的 SMTP 服务器不是 Exchange 的一部分,但无论如何都需要注意。

回答by Andreas Haferburg

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.

我让它工作的方式是在 Outlook (2016) 中单击“到...”按钮,然后在全局地址簿中搜索 ML。有两个条目,一个带有地球符号,一个带有人物符号。

enter image description here

在此处输入图片说明

Right click the one with the globe, select Properties. Here you can find the email address.

右键单击带有地球的那个,选择属性。您可以在此处找到电子邮件地址。