请不要将此标记为重复。我可以找到与此相关的很多问题,但是没有一个对我有帮助。以下是我在 C# 应用程序中用于发送电子邮件的内容,但出现异常:
连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应 74.125.129.108:587
我的代码是:
try {
var client = new SmtpClient("smtp.gmail.com", 587) {
Credentials = new NetworkCredential("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d656565657d5a505c5451135e5250" rel="noreferrer noopener nofollow">[email protected]</a>", "XXXX"),
EnableSsl = true
};
client.Send("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ebb3b3b3b3ab8c868a8287c5888486" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bee6e6e6e6fed9d3dfd7d290ddd1d3" rel="noreferrer noopener nofollow">[email protected]</a>", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();
}
catch
{ }
最佳答案
检查该端口是否被您的防火墙阻止,尤其是您的公司防火墙未被阻止。
根据您的需要,有许多端口扫描仪可用,这里有一个 suggestion让您开始。
关于c# - 发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17341121/