码迷,mamicode.com
首页 > 其他好文 > 详细

django使用gmail

时间:2016-01-28 20:54:26      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

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 = ‘youremail@gmail.com‘
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=[‘youremail@somewhere.com‘])
Edit: Bryan commented that send_mail is deprecated. Use EmailMessage instead:

>>> from django.core.mail import EmailMessage
>>> email = EmailMessage(‘Hello‘, ‘World‘, to=[‘youremail@somewhere.com‘])
>>> email.send()

django使用gmail

标签:

原文地址:http://www.cnblogs.com/cmsd/p/5167339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!