Can't auth to Gmail smtp via MailMessage & smtpClient

PositiveGuy picture PositiveGuy · Feb 1, 2012 · Viewed 35.7k times · Source

I cannot figure out for the life of my why this isn't working

SmtpClient smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    UseDefaultCredentials = false,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    Credentials = new NetworkCredential("[email protected]", "myGmailPasswordHere"),
    EnableSsl = true,
    Timeout = 10000
};


smtp.Send(mail);

I get:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

I just specified EnableSsl to true so that shouldn't be the issue in terms of secure connection.

I'm running this from localhost. And yes, my username and password I'm entering to auth (my gmail account credentials) is 100% right.

Answer

Tiny picture Tiny · Aug 20, 2014

I know this is an old topic, BUT... Google has changed something on their security settings.

Was struggling with all the answers until I checked my email with a mail from Google stating that "we've recently blocked a sign-in attempt on your Google account".

That led me to this page: Google Account Security

Under the "Access for less secure apps" section, you can enable access to your account from other devices/applications... like your C# application.

Note, there is no longer an "application specific" section.

Hope this helps someone... I just lost 30 minutes of my life...