Send_mail在Django中,在shell中工作,在本地工作,不在视图中 [英] Send_mail in Django, works in shell, works locally, not in view
问题描述
我甚至不知道如何调试:我在Django中的一个视图中使用send_mail。在本地使用应用程序(使用我在生产中使用的相同的SMTP设置)时,它可以正常工作,并且在生产中从shell(再次使用相同的设置)可以正常工作。但是,当我实际使用该应用程序在生产中时,该消息不发送。任何想法如何解决问题?
I'm not even sure how to debug this: I'm using send_mail in one of my views in Django. It works fine when using the app locally (using the same SMTP settings I use in production), and it works fine from the shell in production (again, using the same settings). But when I actually use the app in production, the message doesn't send. Any idea how to troubleshoot?
我不会粘贴在整个视图中,但这里是相关部分。
I won't paste in the whole view, but here's the relevant section.
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文件中的相关位,为了安全起见,更改了显着的细节:
And here's the relevant bits from my local_settings file, with salient details altered for security's sake:
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'
推荐答案
你可以尝试django-sendgrid而不是非常容易配置。使用这样的设置
You can try django-sendgrid instead which is very easy to configure.Use settings like this
EMAIL_BACKEND = "sgbackend.SendGridBackend"
SENDGRID_USER = 'xxxxxx'
SENDGRID_PASSWORD = 'xxxxxx'
EMAIL_PORT = 1025
这篇关于Send_mail在Django中,在shell中工作,在本地工作,不在视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!