在Django中发送邮件 (using gmail)

Friday, January 29, 2010

在django中配置使用gmail来发送邮件,只要在setting.py文件中加入

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = '25'
EMAIL_HOST_USER = 'username'  #加username@gmail.com也可以。
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True

测试:

python manage.py shell

In [1]: from django.core.mail import send_mail
In [2]: send_mail('Subject', 'Body of the message.', 'from_username@gmail.com',['to_username@gmail.com'])
Out[2]: 1#输出一表示成功

ps: 改过setting中的参数需要exit()退出shell,再次python manage.py shell进入。

发送 HTML 邮件

This entry was tagged Django and Python

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top