已达到错误限制当试图用SmtpClient发送电子邮件时

本文关键字:SmtpClient 电子邮件 错误 | 更新日期: 2023-09-27 18:19:15

我收到"服务不可用,关闭传输通道"。当我尝试使用c#代码发送邮件时,服务器的响应是:Error limit reached .

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部分。有人能帮我吗?对不起,我的英语不好。

已达到错误限制当试图用SmtpClient发送电子邮件时

根据我的经验

服务不可用,正在关闭传输通道。服务器的响应是:Error limit reached

如果你试图发送大量电子邮件会被解雇-听起来逻辑正确:-)

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

我的观点是:使用在邮件服务器上注册的电子邮件,并注意限制,在某些情况下,仅通过在调试时运行代码就可以达到。

试试这个…

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;
}