首页 > 解决方案 > c# SM​​TP 代码工作,移动到另一台服务器不起作用

问题描述

我有代码可以发送运行良好的电子邮件。我们更改了托管公司,因此我们将主机和端口更改为新要求,它不会发送电子邮件。我们尝试了各种不同的设置,但都没有运气。

我需要指出的是,如果我们在 iPhone 和 Outlook 上使用完全相同的设置,它就可以正常工作。

这是我正在使用的代码:

        SmtpClient client = new SmtpClient();
        client.Host = "Host name";         // Tried named and IP address.
        client.Port = 587;
        client.EnableSsl = false;          // Tried both true and false.
        client.UseDefaultCredentials = false;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Credentials = new System.Net.NetworkCredential(strFrom, strSMTPPassword);
        client.Timeout = 100000;
        mail.IsBodyHtml = true;

        try
        {
            client.Send(mail);
        }
        catch (Exception ex)
        {
        }

它总是失败。最近一次我们收到以下异常消息:

Main: "Failure sending mail."
Inner Exception: "Unable to connect to the remote server"
Inner exception of that: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond <PI:Port>"

我们正在使用 C#、ASP.Net、.Net v 4.5。

有人有什么想法吗?就像我说的 - 它可以在 Outlook 和 iPhone 中运行,并且此代码在更改托管公司之前就可以运行。

TIA。

J。

标签: c#asp.netemailsmtp

解决方案


推荐阅读