Django send_mail不工作 [英] Django send_mail not working

查看:120
本文介绍了Django send_mail不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当发送电子邮件的视图没有任何反应时,我然后输入send_mail(...)到python shell中,它返回1,但是我没有收到任何电子邮件。

When the view that sends the email is used nothing happens, i then entered send_mail(...) into the python shell and it returned 1 but i didn't receive any emails.

这是我的settings.py

This is my settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'workorbit@gmail.com'
EMAIL_HOST_PASSWORD = 'P@ssw0rd5'
EMAIL_USE_TLS = True

这是视图:

def send_email(request):
    send_mail('Request Callback', 'Here is the message.', 'workorbit@gmail.com',
        ['charl@byteorbit.com'], fail_silently=False)
    return HttpResponseRedirect('/')


推荐答案

调整您的设置:

DEFAULT_FROM_EMAIL = 'workorbit@gmail.com'
SERVER_EMAIL = 'workorbit@gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'workorbit@gmail.com'
EMAIL_HOST_PASSWORD = 'P@ssw0rd5'

调整代码:

from django.core.mail import EmailMessage

def send_email(request):
    msg = EmailMessage('Request Callback',
                       'Here is the message.', to=['charl@byteorbit.com'])
    msg.send()
    return HttpResponseRedirect('/')

这篇关于Django send_mail不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆