SmtpClient:A连接尝试失败,因为连接的方没有正确一段时间后,响应 [英] SmtpClient: A connection attempt failed because the connected party did not properly respond after a period of time
问题描述
虽然有电子邮件在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
但同样的代码在其他一些PC工作正常,但是当我今天测试它给我的错误在发送()
方法...还我的网络连接良好,其中i正在测试的电子邮件代码..
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:A连接尝试失败,因为连接的方没有正确一段时间后,响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!