Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

python - Django 1.8 sending mail using gmail SMTP

I was trying send a mail using smtp.gmail.com in django 1.8

My settings.py contains:

EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'  
EMAIL_HOST='smtp.gmail.com'  
EMAIL_PORT=465  
EMAIL_HOST_USER = 'sarath4coding'  
EMAIL_HOST_PASSWORD = '*********'  
DEFAULT_EMAIL_FROM = '[email protected]'
from django.core import mail
mail.send_mail('subject','message','[email protected]',['[email protected]'])

But got this error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django_smtp_ssl.py", line 14, in open
    self.connection.login(self.username, self.password)
  File "/usr/lib/python2.7/smtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuze
5.7.14 2FDKQt2Dlo2vqFIvbr6DnBItwWvh9DChPwbeTZO66N91gzmiA437Vqs80cZ9-8u13vxq5a
5.7.14 bVahzO_BQcZ53yKbJ-YbAlmFE1XIK7MfH97O0wI1lvzpTG_WAHuTIBF0HD1GA2icUoUemt
5.7.14 ErZn4qb942aAIMG103FnrzLp4txXTbXC-wGLpaz5yvnUN5thahvv3-RiIVW8F1QddZKZlg
5.7.14 qQKpqWw56zr1AcO2s_oaBEt556fQ> Please log in via your web browser and
5.7.14 then try again.
5.7.14  Learn more at
5.7.14  https://support.google.com/mail/answer/78754 kx14sm6579665pab.0 - gsmtp')

I tried everything the document says and followed many suggested solutions.

like https://accounts.google.com/DisplayUnlockCaptcha, enabling low security apps etc.

but I still got errors

Can anybody tell how to properly configure Django 1.8 to send mail using Gmail.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

for me in settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'test'
EMAIL_PORT = 587

and views.py:

from django.core.mail import EmailMessage

email = EmailMessage('title', 'body', to=[email])
email.send()
    

and: https://accounts.google.com/DisplayUnlockCaptcha

and also make sure you turn on permission for less secure apps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...