对“421 连接此时不接受”进行故障排除使用 SmtpClient 发送电子邮件时出错

发布于 2024-10-16 05:55:25 字数 981 浏览 6 评论 0原文

我正在尝试使用我的 ISP 发送 4 封电子邮件。 (不是垃圾邮件,我将其发送到我的地址)
我从循环中将它们一一发送(当我构建它们时)。每条消息都是 50kb-80kb

 MailMessage mailmessage = new MailMessage();
 mailmessage.To.Add(to);
 mailmessage.From = new MailAddress(from, "From");
 mailmessage.IsBodyHtml = true;
 mailmessage.Priority = MailPriority.Normal;
 mailmessage.Subject = subject;
 mailmessage.Body = body;
 SmtpClient smtpclient = new SmtpClient(server, 25); //use this PORT!
 smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtpclient.Credentials = new NetworkCredential(user, pass);
 smtpclient.Send(mailmessage);

在最后一条消息中我收到此错误:

服务不可用,正在关闭 传输通道。服务器 响应是:连接不被接受 此时

更新:
有时,出现此错误后,即使从 Outlook Express 等其他应用程序,我也无法发送任何电子邮件(使用此服务器),我收到错误:

发生未知错误。 帐户:“邮件服务器地址”,服务器: '邮件服务器地址'',协议:SMTP, 服务器响应:'421 连接失败 此时接受',端口:25, 安全(SSL):否,服务器错误:421, 错误号:0x800CCC67

大约一分钟后,我可以再次发送。

I am trying to send 4 emails using my isp. (NOT JUNK MAIL, i send it to my address)
I send them one by one from a loop (as I build them). every message is 50kb-80kb

 MailMessage mailmessage = new MailMessage();
 mailmessage.To.Add(to);
 mailmessage.From = new MailAddress(from, "From");
 mailmessage.IsBodyHtml = true;
 mailmessage.Priority = MailPriority.Normal;
 mailmessage.Subject = subject;
 mailmessage.Body = body;
 SmtpClient smtpclient = new SmtpClient(server, 25); //use this PORT!
 smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtpclient.Credentials = new NetworkCredential(user, pass);
 smtpclient.Send(mailmessage);

On last message I get this error:

Service not available, closing
transmission channel. The server
response was: Connection not accepted
at this time

UPDATE:
some times after this error , I can't send any email (using this server) even from other applications like outlook express, I get error:

An unknown error has occurred.
Account: 'MailServerAddress', Server:
'MailServerAddress'', Protocol: SMTP,
Server Response: '421 Connection not
accepted at this time', Port: 25,
Secure(SSL): No, Server Error: 421,
Error Number: 0x800CCC67

after about a minute, I can send again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨# 2024-10-23 05:55:25

始终确保您的发件人地址也是有效的邮箱,以便退回邮件实际上返回给您,许多 ISP 完全禁止使用其他(未注册)发件人地址。正如其他人的评论中所指出的,ISP 通常也会进行速率限制,因此您必须根据 ISP 的期望微调发送代码,这可能很乏味。

一般来说,出于某种原因,发送电子邮件既是艺术也是科学。如果您尝试将其用于生产系统,我只能建议您使用一些服务,例如 SendGrid 或 < a href="http://mailgun.net/" rel="nofollow">Mailgun。即使您的邮件服务器接受邮件,它也可能会遇到另一个 ISP 邮件服务器的限制,因为大多数 ISP 都有一定的限制,并且电子邮件路由非常复杂。此外,您可能会很快遇到垃圾邮件过滤器。对于我的 ISP,无论出于何种原因,自动邮件总是会在 googlemail 中成为垃圾邮件。

对于开发来说,Mailgun 每天免费提供 200 封电子邮件,这在开始时应该足够了。此外,SMTP 是一种非常慢的协议,因此使用其 HTTP 接口将为您节省一些服务器时间。

Always make sure your sender address is also a valid mailbox so bounce messages actually get back to you, many ISPs prohibit use of other (unregistered) sender addresses entirely. As pointed out in the comments by others, there is typically also rate limiting by the ISP so you'll have to fine-tune your sending code to the ISPs expectations, which can be tedious.

In general, sending emails is both art and science for some reason. If you're trying to use this for a production system, I can only suggest you use some service such as SendGrid or Mailgun. Even if your mail server accepts the messages, it might hit a limit on another ISPs mail server because most ISPs have certain limits and email routing is quite complicated. Also you might hit spam filters quickly. With my ISP, automated messages always to go spam in googlemail for whatever reason.

For development, Mailgun offers a two hundred emails per day for free which should be enough in the beginning. Also, SMTP is a very slow protocol so using their HTTP interface will save you some server time.

烟织青萝梦 2024-10-23 05:55:25

我在这里遇到了不完全但非常相似的问题:

SMTP send email failure by SmtpClinet(SmarterEmail 服务器)

问题是我的本地 ISP 正在关闭 25 端口。

您是否测试过其他端口,例如 587?

I had not exactly, but very similar issue here:

SMTP send email failure by SmtpClinet (SmarterEmail server)

The problem was that my local ISP was closing 25 port.

Have you tested some other ports, like 587?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文