C# 如何在不使用 smtp 的情况下通过 Exchange 服务器发送电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1347649/
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 15:27:51  来源:igfitidea点击:

How to send email via exchange server without using smtp?

c#email

提问by Scott Langham

I'm trying to send an email from c# code via our company's exchange server.

我正在尝试通过我们公司的交换服务器从 c# 代码发送电子邮件。

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("exchangebox1.mycompany.com");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("[email protected]",
                "[email protected]",
                "title here",
                "body here");
            client.Send(msg);

When I run this I get SmptException saying "Service not available, closing transmission channel. The server response was 4.3.2 Service not available, closing transmission channel".

当我运行它时,我得到 SmptException 说“服务不可用,正在关闭传输通道。服务器响应是 4.3.2 服务不可用,正在关闭传输通道”。

I'm interpreting this to mean SMTP is not enabled on our exchange box and that I need to use native Exchange Server commands to send the mail. Is this right, or should SMTP always work?

我将此解释为我们的交换盒上未启用 SMTP,我需要使用本机 Exchange Server 命令来发送邮件。这是正确的,还是 SMTP 应该始终有效?

Additionally, is it possible the exchange server could have been configured to only allow certain computers/users to send main via SMTP?

此外,是否有可能将交换服务器配置为仅允许某些计算机/用户通过 SMTP 发送主要内容?

How can I send mail via the Exchange Server without using SMTP?

如何在不使用 SMTP 的情况下通过 Exchange Server 发送邮件?

Thanks.

谢谢。

采纳答案by jasonmw

You can use the WCF Exchange Server Mail Transportan example of how to implement is Here

您可以使用WCF Exchange Server Mail Transport 实现的示例是Here

Specifically regarding sending messages it says

特别是关于发送它说的消息

When an application sends a message, it calls the Send method on the current output channel, which must be open. The output channel serializes the message to a string and creates the message in the Drafts folder. It sets the appropriate values in the e-mail fields. When the message has been created, it is moved into the Outbox. This occurs through CEMAPI on the device or through Exchange Web Services on the desktop. On the device, messages in the Outbox are synchronized with other outgoing messages, as defined by ActiveSync.

当应用程序发送消息时,它会调用当前输出通道上的 Send 方法,该通道必须是打开的。输出通道将消息序列化为字符串并在草稿文件夹中创建消息。它在电子邮件字段中设置适当的值。创建消息后,它会移动到发件箱中。这通过设备上的 CEMAPI 或桌面上的 Exchange Web 服务发生。在设备上,发件箱中的消息与 ActiveSync 定义的其他传出消息同步。

回答by Austin Salonen

Try adding these two lines prior to sending:

尝试在发送之前添加这两行:

client.UseDefaultCredentials = true;
client.EnableSsl = true;

It's most likely an issue with there being no credentials so I'll cheat a little from Google...
From dailycode.net

这很可能是没有凭据的问题,所以我会从谷歌那里作弊......
来自dailycode.net

回答by Terry

You can use the new Exchange Web Services Managed API 1.0. it seems to be the best solution. heres the link.

您可以使用新的 Exchange Web 服务托管 API 1.0。这似乎是最好的解决方案。继承人的链接。

http://msdn.microsoft.com/en-us/library/dd637749(v=exchg.80).aspx
https://blogs.technet.com/b/exchange/archive/2009/04/21/3407328.aspx
The accept will accept distribution lists as well.

http://msdn.microsoft.com/en-us/library/dd637749(v=exchg.80).aspx
https://blogs.technet.com/b/exchange/archive/2009/04/21/3407328。 aspx
接受也将接受分发列表。

The 2.0 version of the API
http://msdn.microsoft.com/en-us/library/office/dd633709.aspx

2.0 版本的 API
http://msdn.microsoft.com/en-us/library/office/dd633709.aspx

回答by mkinawy

I know this is an old thread, but for completeness, you should consider the Microsoft Exchange WebServicesnuget package:

我知道这是一个旧线程,但为了完整起见,您应该考虑Microsoft Exchange WebServicesnuget 包:

https://www.nuget.org/packages/Microsoft.Exchange.WebServices

https://www.nuget.org/packages/Microsoft.Exchange.WebServices

ExchangeService service = new ExchangeService();  
service.AutodiscoverUrl("[email protected]");  

EmailMessage message = new EmailMessage(service);  
message.Subject = "my subject";  
message.Body = "my body";  
message.ToRecipients.Add("[email protected]");  
message.Save();  

message.SendAndSaveCopy();