C# 发送电子邮件代码突然停止工作

发布于 2024-11-06 01:54:34 字数 1032 浏览 0 评论 0原文

我有以下代码,几个月来一直工作正常,但突然停止在这条线上工作:

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

芯好空 2024-11-13 01:54:34

您连接的邮件服务器已被严格限制,不允许中继您的凭据或来自您的网络/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.

找个人就嫁了吧 2024-11-13 01:54:34

除了检查以确保 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文