我甚至不知道如何調試:我在Django中的一個視圖中使用send_mail。在本地使用應用程序時它工作正常(使用我在生產中使用的相同SMTP設置),並且它在生產中的shell(再次使用相同的設置)正常工作。但是當我在生產中實際使用該應用程序時,該消息不會發送。任何想法如何排除故障?Django中的Send_mail,在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, '[email protected]', ['[email protected]', invitation.user.email], fail_silently=True)
而這裏的相關位從我LOCAL_SETTINGS文件,以改變爲安全起見突出的細節:
EMAIL_HOST = 'mail.mydomain.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'p4ssw0rd'
歡迎來到SO!您是否嘗試過使用'fail_silently = False'並尋找任何'SMTPException'? –
謝謝César!我確實嘗試了將fail_silently標誌設置爲False(本地,生產shell和生產中的應用程序),並且在任何時候都沒有捕獲到SMTPExceptions。 (我假設生產中的應用程序會將該異常寫入錯誤日誌。) – mthomps