SmtpClient:连接尝试失败,因为连接方在一段时间后没有正确响应

发布于 2024-11-29 22:48:48 字数 859 浏览 0 评论 0原文

在 Visual Studio 2008 中使用 C#.NET 发送电子邮件时,出现以下错误

连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应 74.125.53.108:25

但相同的代码在其他 PC 上工作正常,但当我测试时今天它在 Send() 方法中给了我错误...而且我的网络连接很好,我正在测试电子邮件代码。

下面是我的电子邮件代码 出现

MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("[email protected]",
                                                            "MyPassword");
smtp.EnableSsl = true;
smtp.Send(mail);

此类错误的原因可能是什么.. ???

While working with Email sending in C#.NET in visual studio 2008 i got the below error

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 74.125.53.108:25

But the same code was working fine in some other PC but when i am testing today it gives me error in Send() method... Also my network connection is good where i am testing the email code..

Below is my email code

MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("[email protected]",
                                                            "MyPassword");
smtp.EnableSsl = true;
smtp.Send(mail);

What could be the reasons for such error..???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

疏忽 2024-12-06 22:48:48

以下代码对我有用。您的代码给了我错误,我相信这是由于没有将端口设置为 587。

http://forums.asp.net/t/1250771.aspx/4/10

MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(address, password);
smtp.Send(mail);

The following code works for me. Your code was giving me errors, I believe it was due to not setting the port to 587.

http://forums.asp.net/t/1250771.aspx/4/10

MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(address, password);
smtp.Send(mail);
浊酒尽余欢 2024-12-06 22:48:48

由于我公司的安全无线网络,我发生了这种情况。一旦我更改为打开wifi,问题就自动解决了。

This happened to me due to my company security wifi. Once I changed to open wifi, the problem was solved automatically.

久光 2024-12-06 22:48:48

这是一个防火墙问题,添加一条规则来绕过您的 IP/应用程序服务器的 IP 即可解决此问题,并且能够连接到 SMTP 服务器。

This was a firewall issue, adding a rule to bypass your IP / IP of application server resolves this and is able to connect to the SMTP server.

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