`
zl4393753
  • 浏览: 333392 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Using gmail to send e-mails from Django

 
阅读更多
To send an e-mail through django's SMTP server you just have to define a few variables in your settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'pw'
EMAIL_PORT = 587
EMAIL_USE_TLS = True


You can test to make sure your settings work properly by loading up the python interpreter:

$> ./manage.py shell
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['user@gmail.com'])
email.send()


If you define a wrong EMAIL_HOST like 'gmail.com' instead of 'smtp.gmail.com' email.send() will just sit there and churn and not give you a response back.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics