C# 发送电子邮件代码突然停止工作
我有以下代码,几个月来一直工作正常,但突然停止在这条线上工作:
smtpClient.Send(msg);
这是一个内部应用程序,向我公司的内部人员发送电子邮件,
并出现以下错误:
邮箱不可用。服务器响应为:5.7.1 无法中继[电子邮件受保护]
谁能想到为什么这段代码可以正常工作很长时间却突然停止工作的原因吗?
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromEmailAddress_);
msg.IsBodyHtml = true;
msg.To.Add(new MailAddress(email.Trim()));
msg.Subject = subject_;
msg.Body = body_;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
var smtpClient = new SmtpClient(_mailServer);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(_user, _pwd);
try
{
smtpClient.Send(msg);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
i have the following code that has worked fine for months but suddently stopped working on this line:
smtpClient.Send(msg);
this is an internal application sending emails to internal people in my company
with the following error:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for [email protected]
can anyone think of a reason why this code would work fine for ages and suddently just stop work ?
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromEmailAddress_);
msg.IsBodyHtml = true;
msg.To.Add(new MailAddress(email.Trim()));
msg.Subject = subject_;
msg.Body = body_;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
var smtpClient = new SmtpClient(_mailServer);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(_user, _pwd);
try
{
smtpClient.Send(msg);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您连接的邮件服务器已被严格限制,不允许中继您的凭据或来自您的网络/IP。这不是代码问题(除了更改 SMTP 服务器),而是管理您正在使用的 SMTP 服务器的人的问题或疑问。
The mail server you're connecting to has been tightened up to not allow relaying either for your credentials or from your network/IP. This is not a code issue (short of changing the SMTP server) but an issue or question for whoever manages the SMTP server you're using.
除了检查以确保 smtp 服务正在运行之外,您还可以尝试以下操作:
尝试将 SmtpDeliveryMethod 枚举设置为 PickupDirectoryFromIis。
http://msdn.microsoft.com/en-us /library/system.net.mail.smtpdeliverymethod.aspx
Apart from checking to ensure the smtp service is running you can try the following:
Try setting the SmtpDeliveryMethod enum to PickupDirectoryFromIis.
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpdeliverymethod.aspx