Unable to send mail through smtp.gmail.com

March 10, 2014 49.3k views
I have recently become unable to send any e-mail from my Django app hosted on a DO droplet through smtp.gmail.com. Any time I try, I get the following error message: SMTPAuthenticationError (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 sh5sm32272477pbc.21 - gsmtp') Which is weird, because the username and password used works perfectly when I try to log in manually, or when sending through the exact same Django app from localhost. I have also tried going through http://www.google.com/accounts/DisplayUnlockCaptcha , as mentioned in the Google support answer. I have been sending at maximum a couple of hundred e-mail in total from that account, with maybe ~10 a day - so abuse seems to be out of the question for me. I should mention that the account is a paid Google Apps account. The fact that I can use the exact same settings while using localhost as a server, plus the fact that this error has only appeared recently, makes me think that the error might have something to do with Digital Ocean. Do you have any ideas about what might cause this? Thanks and with the best regards, Martin Ps. for good measure, here are my smtp settings, minus the password (which I am 100% sure is correct): EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = 'info@CoCreately.com' EMAIL_HOST_PASSWORD =
  • We are experiencing the same issue. We can be sure that the Gmail server settings and code is correct, as our production server (on different infrastructure, same domain) works fine and is currently sending emails. Only our development server which is hosted on Digital Ocean fails to send emails and gets the same message listed above.

    Is it possible that the Digital Ocean subnet has been blacklisted by Gmail?

  • Any resolution for this issue?. Two of my earlier deployments work fine, but the newest one is giving this issue. Can't find a resolution

  • Same issue with my droplet. Anyone can help?

  • encountered the same issue. But solved after generating a new app password for Digital Ocean server from here https://security.google.com/settings/security/apppasswords and using it.

  • any update abount this error, i mean, at cakephp -> EmailTransport same description, but i have this error.
    SMTP server did not accept the password. Cake\Network\Exception\SocketException

  • @omarg55 you need to turn on "Access for less secure apps" on the gmail account you are trying yo use

  • @cartocri it is ready "Access for less secure apps", but again warming SMTP server did not accept the password.
    'EmailTransport' => [
    'default' => [
    'className' => 'Smtp',
    // The following keys are used in SMTP transports
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'timeout' => 30,
    'username' => 'xxx@gmail.com',
    'password' => 'xxx',
    //'client' => null,
    //'tls' => true,

  • Google now doesn't accept login from less secure apps. So you need to go to https://myaccount.google.com/security scroll to the bottom and turn ON "Allow less secure apps: ON". Now when you add the SMTP details to "Send as" google will accept them. You need to do this for the email ID you are adding in your Send as section.

14 Answers
I believe gmail limits the amount of emails you can send per day. You probably passed that limit. I recommend using a transactional mail service such as Mandrill or SendGrid.
I have the same issue running CakePHP, and completely sure that it's not a GMAIL ban, because i have the exactly same app running in another server and it is still sending emails... : (

I had the same problem. I guess it's a gmail ban, because the Gmail send a mail with this link: https://support.google.com/mail/answer/14257?p=client_login&rd=1

The point is this: https://www.google.com/settings/security/lesssecureapps

You should change the "Access for less secure apps" to Enabled (it was enabled, I changed to disabled and than back to enabled). After a while I could send email.

Hey guys, just found what's going on with those errors.

The problem is that when you have activated the Google Authenticator Verification you also need to set up the 2-Step-Authentication in your gmail account.

Therefore visit https://www.google.com/settings/security - when you have done so, just go back to this page and click the "App Password" - Settings.

Select "Other (custom name)" and enter any name you like. Go ahead and copy the code and paste it to your projects settings.

Done! - This resolved all issues for me.

Greets P4rks!

Same issue here, although my application is a Ruby on Rails 3.2 app.

The code was working for months, and stopped working in the past few days.

Same problem here.

localhost --> can send mails
upload applicaton to droplet --> can not send mails

https://github.com/andris9/Nodemailer/issues/192 and search for user: aco7342

  • remember this droplet has smtp facilities request by email to digital ocean

I too ran into this problem today. I confirmed through my /var/log/mail.log that the connection happens, the username and password are sent (correct credentials), but the response is always:

535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 u8sm6322553qat.27 - gsmtp

I tried with an account that is in use in a different environment as well as with a brand new account within my google apps domain. Neither account worked.

Hey P4rks,

Your solution was accurate and it worked for me as well. Infact, this 2 step authentication is great because now you can have different passwords for different devices.


It works with password generated. Thank you. :)

HI P4rs,
I have the same problem. I fallowed your instructions. This works good on my local host. But when i use same on my live it give me error "535 Incorrect authentication data". I believe that it is due to location of my live server. But what will be the solution for this?

Thanks in advance,

For me the problem was not auth but the mail with valid URL inside.
I removed the urls and everything is fine.

  1. Go to admin.google.com
  2. From the admin console, select “Security”
  3. Select “Basic settings”
  4. Scroll down to “Less secure apps”
  5. Go to settings for less secure apps ››
  6. Check the radio button “Allow users to manage their access to less secure apps”
  7. Save the changes
  8. Open this link being sign in as the super administrator https://www.google.com/settings/security/lesssecureapps
  9. Check the radio button Turn On the access for less secure apps
  10. Unlock Captcha using this link https://accounts.google.com/DisplayUnlockCaptcha

There's some changes from google security on Google Apps or gmail accounts.

To avoid the issue i had solved with the following steps:

1.Login into your account Gmail or Google Apps then goto:


and Turns On the Access for less secure apps.

Have another answer? Share your knowledge.