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..???
Change the server's SMTP restrictions. Then, add the specified website user to the list of users who are authorized to initiate outbound SMTP connections. Edit PHPMailer's configuration settings, such as host and port. Correct DNS resolution for the mail server.
From the Authentication Method list, select the method to authenticate the SMTP client to the SMTP server. In the Account Name field, enter the account or user name of the SMTP client to authenticate on the SMTP server. Generally, the account takes the name @ domain .com form.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With