【问题标题】:Got "Error limit reached" while trying to send email with SmtpClient尝试使用 SmtpClient 发送电子邮件时出现“达到错误限制”
【发布时间】:2014-08-26 17:51:31
【问题描述】:

当我尝试使用 C# 代码发送邮件时,我收到“服务不可用,正在关闭传输通道。服务器响应为:达到错误限制”。

try
{
    MailMessage emailMessage = new MailMessage();

    emailMessage.Subject = "smth subject";

    messages = string.Empty;

    string serverName = System.Environment.MachineName;
    string serverIpAddress = Dns.GetHostAddresses(Environment.MachineName)
                                .First(ip => ip.AddressFamily == AddressFamily.InterNetwork).ToString();

    string serverNameWithDetails = Settings.Default.ServiceDisplayName + " (server's name: " + serverName + ", server's ip address: " + serverIpAddress + ")";

    emailMessage.IsBodyHtml = true;
    emailMessage.Body = "smth body";
    emailMessage.From = new MailAddress(config.SmtpUser);
    emailMessage.To.Add("myAddress@aaa.com");

    // Set encoding
    emailMessage.HeadersEncoding = System.Text.Encoding.UTF8;
    emailMessage.BodyEncoding = System.Text.Encoding.UTF8;

    SmtpClient smtpClient = new SmtpClient(config.SmptHost, config.SmptPort);

    NetworkCredential smtpUserInfo = new System.Net.NetworkCredential(config.SmtpUser, config.SmtpPassword);
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = smtpUserInfo;

    smtpClient.Send(emailMessage);

    EmailSent = true;
}
catch (Exception e)
{
    log.ErrorFormat("The following error occured while building and sending the email: {0}", e.Message);
}

所以 e.Message 是上面写的错误,但我找不到有关此错误消息的任何信息。 当smtpClient.Send(emailMessage); 行被执行时,它进入catch 部分。 谁能帮我? 对不起我的英语不好。

【问题讨论】:

    标签: c# asp.net smtp smtpclient


    【解决方案1】:

    根据我的经验

    服务不可用,正在关闭传输通道。服务器响应是:达到错误限制

    如果您尝试发送大量电子邮件,就会被解雇 - 听起来很合乎逻辑:-)

    棘手的部分是某些 ISP 的限制可能非常低(每小时 20 - 500 封不同的邮件),如果您将发件人声明为未注册的电子邮件,则在邮件服务器上,限制可以为 0 ,然后触发这种错误信息。

    我的意思是:使用在邮件服务器上注册的电子邮件,并注意限制,在某些情况下,只需在调试时运行代码即可达到限制。

    【讨论】:

      【解决方案2】:

      试试这个..

      using System.Net;
      using System.Net.Mail; 
      string to = strSidMail;
      string from = "rajeeshmenoth@wordpress.com";
      
      MailMessage message = new MailMessage(from, to);
      message.Subject = txt_subject.text;
      message.Body = mailbody;
      message.BodyEncoding = Encoding.UTF8;
      message.IsBodyHtml = true;
      SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
      System.Net.NetworkCredential basicCredential1 = new
      System.Net.NetworkCredential("yourgmail id", "Password");
      client.EnableSsl = true;
      client.UseDefaultCredentials = false;
      client.Credentials = basicCredential1;   
      try
      {
      client.Send(message);
      }
      catch (Exception ex)
      {
      throw ex;
      }
      

      【讨论】:

      • 我更改了客户端的 smtp 密码,似乎一切正常。我不知道我是否解决了这个问题,我会注意日志,我希望它不会再次发生。无论如何,感谢您的帮助!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 2014-09-15
      • 2022-06-13
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多