c# - c# SMTP 代码工作,移动到另一台服务器不起作用
问题描述
我有代码可以发送运行良好的电子邮件。我们更改了托管公司,因此我们将主机和端口更改为新要求,它不会发送电子邮件。我们尝试了各种不同的设置,但都没有运气。
我需要指出的是,如果我们在 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。
解决方案
推荐阅读
- sql - 确定过去 30 天内某个特定字段发生更改的时间。如果在另一个表中找到插入记录
- java - 无法将 csv 文件中的百万条记录插入 MySql 数据库
- sql - 从排名靠前的项目中获取差异
- cmake - CMake:如何从环境中添加 include() 的搜索路径?
- .net - .net5“部署一个独立的应用程序”没有 ssl 的 localhost 证书,没有安装 dotnet
- c# - 将只读结构作为“in”参数传递?
- c - 如何从其他 C 程序访问共享对象(.so)中的全局变量?
- javascript - 发布请求失败后不返回错误 - axios、express、node.js
- python - 调用氦的函数 start_chrome() 时出错
- python - 有条件地循环数据帧