Django:如何发送符合 RFC 822 标准的电子邮件? (用户因空格无法回复)

Django: How to send RFC 822 compliant email? (users can't reply because of whitespace)

一位用户最近通知我他无法回复我的电子邮件,因为地址中有白色 space。他还提到原始 FROM 字段不符合 RFC 822 - 我对此了解不多,无法验证。

这是他收到的原始发件人字段:

From: SiteName someprefix@mg.somesite.io

这是我目前发送这些电子邮件的方式:

msg_plain = render_to_string('email_template.txt', context)
                msg_html = render_to_string('email_template.html', context)

                EMAIL_FROM_FIELD = 'SiteName someprefix@mg.somesite.io'

                mail_was_sent = send_mail(
                    email_subject,
                    msg_plain,
                    EMAIL_FROM_FIELD,
                    [profile.user.email],
                    html_message=msg_html,
                )

我做错了什么?

除非我遗漏了什么,否则我认为你需要更改此设置:

EMAIL_FROM_FIELD = 'SiteName someprefix@mg.somesite.io'

为此:

EMAIL_FROM_FIELD = 'SiteName <someprefix@mg.somesite.io>'

The general rule is that wherever there may be linear-white-space (NOT simply LWSP-chars), a CRLF immediately followed by AT LEAST one LWSP-char may instead be inserted.

本文来自:https://www.w3.org/Protocols/rfc822/

您可以如下定义表单域:

EMAIL_FROM_FIELD = 'SiteName <someprefix@mg.somesite.io>'