C # smtp.google.com cannot be resolved

The 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(" catthoor.jc@gmail.com ", "Jasper.Kattoor"); mail.To.Add("YYYY"); mail.Subject = "sup"; mail.Body = "sup"; smtpServer.Credentials = new NetworkCredential(" catthoor.jc@gmail.com ", "XXXX"); smtpServer.EnableSsl = true; smtpServer.Send(mail); } catch (Exception ex) { Console.WriteLine(ex); Console.ReadLine(); } } 

I get the following error:

System.Net.Mail.SmtpException: Error sending mail. ---> System.Net.WebException: Remote name could not be resolved: 'Smtp.google.com'

I also tried using hotmail instead of gmail, same error. I can still send letters manually. Why does this error suddenly occur? There were no problems with this yesterday.

+7
c # email
source share
1 answer

This remote host name is incorrect, it must be:

 smtp.gmail.com 

Read all about it: Send an Email from Yahoo !, GMail, Hotmail (C #)

Updates . You can also ping the hostname to check if it exists using the command line

enter image description here

+17
source share

All Articles