当我尝试使用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部分。
谁能帮我?
抱歉我的英语不好。
答案 0 :(得分:0)
根据我的经验
服务不可用,关闭传输通道。服务器响应为:达到错误限制
如果您尝试发送大量电子邮件,则会被触发 - 声音逻辑正确: - )
棘手的部分是某些ISP的限制可能非常低(20 - 500个不同的邮件/小时),如果您将发件人声明为未注册的电子邮件,则在邮件服务器上,限制可以为0 ,然后触发此类错误消息。
我的观点是:使用在邮件服务器上注册的电子邮件,并注意限制,在某些情况下,只需在调试时运行代码即可达到这些限制。
答案 1 :(得分:0)
尝试thiz ..
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;
}