简体   繁体   English

尝试在 C# 中发送邮件时收到 SMTP 异常

[英]Recieving an SMTP Exception when Trying to Send Mail in C#

We are receiving an SMTP 4.4.1 connection time out exception every so often when attempting to send mail in C#.尝试在 C# 中发送邮件时,我们经常收到 SMTP 4.4.1 连接超时异常。 So far we have found no pattern as to when the issue occurs, such as the time of day.到目前为止,我们还没有发现问题发生的时间模式,例如一天中的时间。

The exception thrown is:抛出的异常是:

System.Net.Mail.SmtpException: Service not available, closing transmission channel. System.Net.Mail.SmtpException: 服务不可用,正在关闭传输通道。 The server response was: 4.4.1 Connection timed out服务器响应为:4.4.1 连接超时

Up to 30 emails at anyone time are sent and 9 times out of 10 all are sent successfully.任何时候最多可发送 30 封电子邮件,10 次中有 9 次成功发送。 When we run into the 4.4.1 exception a number of the emails are sent and the remaining 1 or 2 are not.当我们遇到 4.4.1 异常时,会发送一些电子邮件,而其余的 1 或 2 封则没有。

Unfortunately, I don't have access to the clients Exchange server, only the application server where our application is running from.不幸的是,我无权访问客户端 Exchange 服务器,只能访问运行我们的应用程序的应用程序服务器。 So I'm working with the host on this.所以我正在与主持人合作解决这个问题。 The Event Log has been checked on the application server, the only thing found was the following warning from a source McLogEvent:已在应用程序服务器上检查事件日志,唯一发现的是来自源 McLogEvent 的以下警告:

Would be blocked by port blocking rule (rule is in warn-only mode) (Anti-virus Standard Protection: Prevent mass mailing worms from sending mail).将被端口阻止规则阻止(规则处于仅警告模式)(防病毒标准保护:防止群发邮件蠕虫发送邮件)。

Has anyone came across this issue before or know of a possible cause?有没有人以前遇到过这个问题或知道可能的原因?

Without any code posted, kind of hard to debug.没有发布任何代码,很难调试。 Have you checked out this similar SO question?你有没有检查过这个类似的问题?

Sending 2000 emails 发送 2000 封电子邮件

I found several SO questions with similar errors.我发现了几个类似错误的问题。 My guess is that your server is trying to send too many emails at once and the connection bombs.我的猜测是您的服务器试图一次发送太多电子邮件并且连接炸弹。 Try sending a handful at a time;尝试一次发送一把; start with one, work your way up to 30 and see if that works.从一个开始,逐步增加到 30 个,看看是否有效。 here's my Google search:这是我的谷歌搜索:

https://www.google.com/search?q=The+server+response+was%3A+4.4.1+Connection+timed+out&rlz=1C1CHFX_en__601US628&oq=The+server+response+was%3A+4.4.1+Connection+timed+out&aqs=chrome..69i57j69i64&sourceid=chrome&es_sm=93&ie=UTF-8 https://www.google.com/search?q=The+server+response+was%3A+4.4.1+Connection+timed+out&rlz=1C1CHFX_en__601US628&oq=The+server+response+was%3A+4.4.1+ Connection+timed+out&aqs=chrome..69i57j69i64&sourceid=chrome&es_sm=93&ie=UTF-8

I had a similar issue.我有一个类似的问题。 We would send 1000+ emails in batches of 50 at a time and it would throw the "4.4.1 Connection timed out" SMTP exception every 10 minutes.我们会一次发送 1000 多封电子邮件,每批 50 封,它会每 10 分钟抛出“4.4.1 连接超时”SMTP 异常。 The issue turned out to be that the SmtpClient wasn't being disposed properly.问题原来是 SmtpClient 没有被正确处理。 Apparently, it doesn't send the "QUIT" SMTP command if you reassign it.显然,如果您重新分配它,它不会发送“退出”SMTP 命令。

Wrong:错误的:

SmtpClient client = new SmtpClient();

Right:对:

using (SmtpClient client = new SmtpClient()) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM