Django email delivery issue though smtp.gmail.com

I am trying to configure Django send_email so that I can send reset passwords to users. So far, I have not been able to get it to work. I set up a basic Gmail account (no Google app, etc.), And in my Django settings.py I have:

EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_PASSWORD = 'my_password' EMAIL_HOST_USER = ' my_account@gmail.com ' EMAIL_PORT = 587 MAIL_USE_TLS = True EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' DEFAULT_FROM_EMAIL = ' admin@my-site.com ' 

Then I will try to verify this by doing:

 python manage.py shell >>> from django.core.mail import send_mail >>> send_mail('test', 'test', ' test@test.com ', [' my-personal-email@gmail.com ']) 

and I get an error

 Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Program Files\Python27\lib\site-packages\django\core\mail\__init__.py ", line 62, in send_mail connection=connection).send() File "C:\Program Files\Python27\lib\site-packages\django\core\mail\message.py" , line 255, in send return self.get_connection(fail_silently).send_messages([self]) File "C:\Program Files\Python27\lib\site-packages\django\core\mail\backends\sm tp.py", line 88, in send_messages new_conn_created = self.open() File "C:\Program Files\Python27\lib\site-packages\django\core\mail\backends\sm tp.py", line 55, in open self.connection.login(self.username, self.password) File "C:\Program Files\Python27\lib\smtplib.py", line 577, in login raise SMTPException("SMTP AUTH extension not supported by server.") SMTPException: SMTP AUTH extension not supported by server. 

Does anyone have an idea what is happening! Any hint is appreciated!

+8
source share
5 answers

You made a typo in your settings. TLS must be set with EMAIL_USE_TLS not MAIL_USE_TLS . Not using TLS when connecting to 587 generates this error.

+19
source

Make sure you also set the EMAIL_BACKEND parameter:

 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 
+6
source

This answer is late to the question; but hopefully helps future readers of this topic.

As @WAF pointed out, EMAIL_USE_TLS = True repairs this error.

In addition, if the permission is checked using the django management tool shell command, we will need to restart the shell after adding the above parameter and repeat the verification steps.

The following is a summary of the minimum configuration for checking gmail from the django shell:

In settings.py:

 EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = '<email.id>' EMAIL_HOST_PASSWORD = '<pw>' EMAIL_USE_TLS = True 

In the django management tool shell:

 from django.core.mail import send_mail send_mail('From django', 'Test email from dj manage', ' from@example.com ', [' to@example.com ']) ... 1 
+2
source

When deleting a mail extension, the error changes to another error. But in most cases this is not a real problem. Once you have set up your installation correctly, it works with and without the extension.

 EMAIL_HOST_USER = 'my_account' 

Visit https://myaccount.google.com/security and see if this works when turned on. Unprotect less secure apps at the bottom.

0
source

This is a problem with your SMTP server configuration. It is not configured with TLS. If you use postfix, refer to the document -
http://postfix.state-of-mind.de/patrick.koetter/smtpauth/postfix_tls_support.html

It would also be useful for you -
How to send an email using Gmail as a provider using Python?

-1
source

Source: https://habr.com/ru/post/957260/


All Articles