I am trying to send email in c# using gmail smtp server but it giving me an error `Failure sending mail“.
Everything is fine username and password. What wrong with this code that can cause this error?
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("myusername@gmail.com", "mypassword"),
EnableSsl = true
};
client.Send("myusername@gmail.com", "myusername@gmail.com", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();
Best Answer
I think this will more helpfull to you https://support.google.com/a/answer/176600?hl=en