我在哪里可以找到可以帮助我找到原因的日志?我有一个配置为将非生产环境电子邮件发送到运行 Mailcatcher 的服务器的 Django 应用程序。当我发送纯文本电子邮件时,它会显示在 Mailcatcher 中,当我添加替代 HTML 内容时,它们不会。
我正在使用EmailMultiAlternatives
并测试这一点,我正在注释掉我的行以attach_alternative()
仅发送文本,它工作正常。runserver 没有错误,并且email.send()
返回 1。
失败:
@staticmethod
def send_payment_confirmation(client, free_trial_days, recur_id):
context = {
'recur_id': recur_id,
'client': client,
'free_trial_days': free_trial_days
}
html_body = render_to_string('email/html/payment_confirmation.html', context)
text_body = render_to_string('email/text/payment_confirmation.txt', context)
email = EmailMultiAlternatives(subject=u"Thank You For Your Payment,{}".format(client.name),
body=text_body, to=[client.get_contact_email()], bcc=['support@example.com'])
email.attach_alternative(html_body, "text/html")
email.send()
作品:
@staticmethod
def send_payment_confirmation(client, free_trial_days, recur_id):
context = {
'recur_id': recur_id,
'client': client,
'free_trial_days': free_trial_days
}
html_body = render_to_string('email/html/payment_confirmation.html', context)
text_body = render_to_string('email/text/payment_confirmation.txt', context)
email = EmailMultiAlternatives(subject=u"Thank You For Your Payment,{}".format(client.name),
body=text_body, to=[client.get_contact_email()], bcc=['support@example.com'])
# email.attach_alternative(html_body, "text/html")
email.send()