Reputation: 625
Following code used to work but suddenly refuses to work.
private static void SendMail()
{
try
{
var mail = new MailMessage();
var smtpServer = new SmtpClient("smtp.google.com", 587);
mail.From = new MailAddress("[email protected]", "Jasper.Kattoor");
mail.To.Add("YYYY");
mail.Subject = "sup";
mail.Body = "sup";
smtpServer.Credentials = new NetworkCredential("[email protected]", "XXXX");
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
}
I receive the following error:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.google.com'
I've also tried using hotmail instead of gmail, same error. I can still send mails manually though. Why would this error suddenly occur? Yesterday there were no problems with this.
Upvotes: 6
Views: 20801
Reputation: 1
Yes, in my case I wasn't just connected to the internet. After I connected the problem was gone.
Upvotes: 0
Reputation: 14899
That remote host name is wrong, it should be:
smtp.gmail.com
Read all about it: Send Email from Yahoo!, GMail, Hotmail (C#)
Updates: You can also ping the host name to check if it exists using command prompt
Upvotes: 18