SmtpClient:连接尝试失败,因为连接方在一段时间后没有正确响应
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下代码对我有用。您的代码给了我错误,我相信这是由于没有将端口设置为 587。
http://forums.asp.net/t/1250771.aspx/4/10
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
由于我公司的安全无线网络,我发生了这种情况。一旦我更改为打开wifi,问题就自动解决了。
This happened to me due to my company security wifi. Once I changed to open wifi, the problem was solved automatically.
这是一个防火墙问题,添加一条规则来绕过您的 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.