SmtpClient:连接尝试失败,因为连接方在一段时间后未正确响应 [英] SmtpClient: A connection attempt failed because the connected party did not properly respond after a period of time

查看:654
本文介绍了SmtpClient:连接尝试失败,因为连接方在一段时间后未正确响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2008中使用C#.NET中的电子邮件发送,我得到以下错误

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


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

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

但同样的代码在一些其他电脑工作正常,但是当我今天测试它给我的错误在 Send()方法...另外我的网络连接是好的,我在哪里正在测试电子邮件代码..

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("MyUserName@gmail.com",
                                                            "MyPassword");
smtp.EnableSsl = true;
smtp.Send(mail);

可能是这样的错误的原因..

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

推荐答案

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

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);

这篇关于SmtpClient:连接尝试失败,因为连接方在一段时间后未正确响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆