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 = '[email protected]'
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=['[email protected]'])
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.

猜你喜欢

转载自zl4393753.iteye.com/blog/1845703