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

2023-09-07 09:56:22 作者:甜甜的吻

虽然有电子邮件在C#.NET发送在Visual Studio 2008的工作我得到了以下错误

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

但是,同样的code是工作的罚款在其他一些PC,但是当我测试今天它给了我错误发送()方法...还有我网络连接好到哪我测试的电子邮件code ..

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..

下面是我的电子邮件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..???

推荐答案

以下code对我的作品。您的code的给我的错误,我相信这是由于没有设置端口为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);