0

我在哪里可以找到可以帮助我找到原因的日志?我有一个配置为将非生产环境电子邮件发送到运行 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()
4

1 回答 1

0

想通了,这是 MailCatcher 的一个已知错误。发送html 电子邮件0.5.12时崩溃后的版本。utf8当前版本是0.6.4- 2/4/16(仍然存在问题)。

降级0.5.12解决问题。

https://github.com/sj26/mailcatcher/issues/201

于 2016-03-17T23:12:39.327 回答