0

(NB This answer to a related question does not provide the kind of information I need: I did all this, and changed my email password to the "app password" in the Django configuration, but the same authentication error still occurred. I need to understand how one gets the Gmail account to recognise which application "send" requests are coming from).

The Google "explanation" page is here. Such as it is.

The problem: I am trying to use a "send mail" function in a Django app (django.core.mail.send_mail).

I have configured the Gmail account I am using so that "Less secure app access" is set to ON. The email address and password are spelled correctly in the code and config files.

I have managed to get this function to work using a strange "captcha"-related URL, as suggested here. BUT... there is a problem with this solution: it appears that this solution does not survive a daemon-reload on my VPS.

In that same Server Fault page someone else suggests configuring using Gmail 2-stage verification, and generating an "app password". I have managed to generate such a password (theoretically for one-off use for authenticating your particular app)... but I have absolutely no idea how to get the Gmail account to "recognise" the app, and somehow set up this "authorisation" for my particular Django app. The explanation for exactly what you do there is not sufficient for someone of my level of expertise.

Please bear in mind the specificity of this problem: I have other Python scripts which use the Python mail module, and these have no problem whatsoever sending an email through this Gmail account. So it appears to be specific to Django and/or something to do with my VPS (hosted at Hostinger).

I am no Django or Web app expert! Far from it. I am floundering.

configuration details

In Django myApp/settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myGmailAccount@gmail.com'
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASSWORD')
EMAIL_PORT = 587

On the server there is an .env file which contains the password:

EMAIL_PASSWORD=mySekret16CharPassword

... where mySekretPassword is the 16-char "app password" generated by Gmail.

This is the authentication error I still get:

smtplib.SMTPAuthenticationError: (534, b'5.7.14 \n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 f198sm3998865qke.46 - gsmtp')

The thing is, when you generate one of these 16-char passwords you are required to enter an application name. I didn't have a clue what to put there: "gunicorn"? "django"? "myapp"? No idea.

1
  • The name you are required to enter is for you to know to which app the generated password refers to, so it doesn’t really matter what you are entering. – Alex May 7 '20 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.