SMTPAuthenticationError sending email via smtp.gmail

9,203 views
Skip to first unread message

bradford li

unread,
Feb 9, 2015, 8:25:59 PM2/9/15
to django...@googlegroups.com
I am trying to have django send emails but I am getting this error:

    Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/Library/Python/2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
        return mail.send()
      File "/Library/Python/2.7/site-packages/django/core/mail/message.py", line 286, in send
        return self.get_connection(fail_silently).send_messages([self])
      File "/Library/Python/2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages
        new_conn_created = self.open()
      File "/Library/Python/2.7/site-packages/django/core/mail/backends/smtp.py", line 59, in open
        self.connection.login(self.username, self.password)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 615, in login
        raise SMTPAuthenticationError(code, resp)
    SMTPAuthenticationError: (534, '5.7.9 Application-specific password required. Learn more at\n5.7.9 http://support.google.com/accounts/bin/answer.py?answer=185833 v14sm3323298pbs.11 - gsmtp')

The link suggested my to perform a 2-step verification which I did but still no results.

In my settings.py

    EMAIL_USE_TLS = True
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_HOST_USER = 'em...@gmail.com'
    EMAIL_HOST_PASSWORD = 'password'
    EMAIL_PORT = 587

I tried testing this in django shell but got the error shown above:

    >>> from django.core.mail import send_mail
    >>> from django.conf import settings
    >>> sub = "sup man"
    >>> msg = "char lisss"
    >>> from_user = settings.EMAIL_HOST_USER
    >>> to = ["em...@email.com"]
    >>> send_mail(sub,msg,from_user,to, fail_silently=False)

François Schiettecatte

unread,
Feb 9, 2015, 8:30:43 PM2/9/15
to django...@googlegroups.com
It does not really have to do with Django, it has to do with OAuth which Google just started enforcing in gmail, you need to relax the security level on the gmail account you are using on this page:

https://www.google.com/settings/security/lesssecureapps

François
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3047e0c7-86f9-477a-be92-76ba53a43225%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

sum abiut

unread,
Feb 9, 2015, 9:18:30 PM2/9/15
to django...@googlegroups.com

Have you tried SendGrid mail. create a sendgrid account and used it instead of gmail.



For more options, visit https://groups.google.com/d/optout.



--

rahul kumar

unread,
Sep 27, 2017, 7:10:34 AM9/27/17
to Django users

It is because Google blocks sign-in attempts from apps which do not use modern security standards (mentioned on their support page). You can however, turn on/off this safety feature by going to the link below:

Go to this link and select Turn On

 

more on...smtp mail 
Reply all
Reply to author
Forward
0 new messages