简体   繁体   中英

gmail not sending email anymore

I was using a gmail account to send email from an app, I have set "allow less secure app", and the list on "Recent Security Events" is empty.

Up until today it was working, but today it started saying:

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

I can still send email using the gmail website and using thunderbird it still works, but not in the app,

if I change in my code the username and password to a different gmail account it works, but not with this particular one.

this is the code I use to send email:

var client = new SmtpClient
{
    Host = serverName,
    Port = 587, // TLS Port
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(userName, pass)
};

using (var message = new MailMessage(new MailAddress(userName), new MailAddress(to))
{
    Subject = subject,
    Body = body
})
{
    client.Send(message);
}

UPDATE: all of a sudden it started to work (on my local, I have unite tests that send email), don't know why, I checked the deployed app it also started to send emails

UPDATE2: seems to be a more global problem: https://productforums.google.com/forum/?nomobile=true&hl=en&utm_source=google-account&utm_medium=web#!topic/gmail/NETOwtLyWGI

In my searchings, I've found a few things to try:

  1. Try changing password to more complex/secure password. On occasion it seems that Gmail starts to require more complex passwords without letting people know and/or throwing proper errors.

  2. Remove "EnableSsl = true," line from code. (or set to false) ( Link )

  3. The fact that your code just stopped working randomly may suggest something along the lines of an expired certificate that is still being presented.

Question: When you say you are able to send email from that account via browser and via Thunderbird, are you sending those emails from the same machine as the C# application attempts to?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM