开发者

Troubleshooting "421 Connection not accepted at this time" error when sending email with SmtpClient

开发者 https://www.devze.com 2023-02-08 16:10 出处:网络
I am tryingto 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

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.


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号