django使用gmail
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django使用gmail相关的知识,希望对你有一定的参考价值。
POSTED ON 02 JUL 2007 IN DEVELOPMENT DJANGO PYTHON WEB
Did a bit of running around today to get Django sending email via Gmail. It’s simple once you figure it out.
If you’re running 0.96, upgrade to the latest development version or apply the patch from ticket #2897. 0.96 does not support TLS, which Gmail requires. Then add the appropriate values to settings.py:
EMAIL_USE_TLS = True
EMAIL_HOST = ‘smtp.gmail.com‘
EMAIL_HOST_USER = ‘[email protected]‘
EMAIL_HOST_PASSWORD = ‘yourpassword‘
EMAIL_PORT = 587
You can use the shell to test it:
>>> from django.core.mail import send_mail
>>> send_mail(‘Test‘, ‘This is a test‘, to=[‘[email protected]‘])
Edit: Bryan commented that send_mail is deprecated. Use EmailMessage instead:
>>> from django.core.mail import EmailMessage
>>> email = EmailMessage(‘Hello‘, ‘World‘, to=[‘[email protected]‘])
>>> email.send()
以上是关于django使用gmail的主要内容,如果未能解决你的问题,请参考以下文章
无法将 Django 设置为与 smtp.gmail.com 一起使用