django使用gmail
2016-01-28 19:56
387 查看
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()
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()
相关文章推荐
- MegaCli查看RAID
- uva10986Sending email (SPFA)
- 如何找回RAID1丢失的数据
- 数据恢复流程
- Service (aidl远程服务)
- LTP 源码分析-- testcases/kernel/containers
- FATAL: DTM initialization: failure during startup recovery, retry failed, check segment status (cdb
- hdu4251The Famous ICPC Team Again【划分树入门题】
- StringUtils.containsOnly使用说明
- How to correctly read data when using epoll_wait
- C++——STL所有算法介绍 http://blog.csdn.net/shinehoo/article/details/5736155
- 关于baidu_tempalate 的使用
- HDFS-RAID
- 通用的contain函数
- Page Rendering - Main Frame and Impl Frame
- 面对谷歌围棋AI,人类最后的智力骄傲即将崩塌
- VS中更改栈和堆空间的大小http://blog.csdn.net/allenjiao/article/details/8516049
- Suricata源码阅读笔记:main()
- windows下绑定线程(进程)到指定的CPU核心 http://blog.csdn.net/beyond_cn/article/details/15813361
- linker command failed with exit code 1 (use -v to see invocation)解决办法