我甚至不确定如何调试这个:我在Django的一个视图中使用send_mail。它在本地使用应用程序时工作正常(使用我在生产中使用的相同SMTP设置),并且它在生产中的shell中工作正常(同样,使用相同的设置)。但是当我在生产中实际使用该应用程序时,该消息不会发送。知道怎么排除故障吗?
我不会粘贴整个视图,但这是相关部分。
if request.method == 'POST':
message, form = decideform(request.POST)
if form.is_valid():
invitation.status = form.cleaned_data['status']
invitation.save()
message, form = decideform(request.POST)
update = 'Thank you for updating your status.'
# Send an email confirming their change
subject = 'Confirming your RSVP [%s %s]' % (invitation.user.first_name, invitation.user.last_name)
body = message + ' Remember, the URL to update or change your RSVP is http://the.url%s.' % invitation.get_absolute_url()
send_mail(subject, body, 'rsvp@mydomain.com', ['rsvp@mydomain.com', invitation.user.email], fail_silently=True)
这是我的local_settings文件中的相关位,为了安全起见改变了显着的细节:
EMAIL_HOST = 'mail.mydomain.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'rsvp@mydomain.com'
DEFAULT_FROM_USER = 'rsvp@mydomain.com'
EMAIL_HOST_PASSWORD = 'p4ssw0rd'
答案 0 :(得分:0)
检查权限。可能是您有权运行send_mail,但应用程序没有。
答案 1 :(得分:0)
我遇到了同样的问题。 3年后:) 复制send_mail的代码内联修复它但我仍然不知道为什么
connection = django.core.mail.get_connection(username=None, password=None, fail_silently=False)
mail = django.core.mail.message.EmailMessage('hello', 'world', 'test@gmail.com', ['test@gmail.com'], connection=connection)
mail.send()
答案 2 :(得分:0)
您可以尝试使用django-sendgrid,这很容易配置。使用这样的设置
EMAIL_BACKEND = "sgbackend.SendGridBackend"
SENDGRID_USER = 'xxxxxx'
SENDGRID_PASSWORD = 'xxxxxx'
EMAIL_PORT = 1025