.Net MailMessage 自动折叠标头字段是否超过 RFC2822 最大长度?

发布于 2024-09-15 19:16:27 字数 254 浏览 6 评论 0原文

请参阅 RFC 2822,第 2.1.1 和 2.2.3 节来启动

System.Net如果 .Mail.MailMessage 的内容超出最大长度限制,会自动折叠其标头字段吗? RFC2822 规定标头字段每行不得超过 998 个字符。为了解决这个问题,可以插入 CRLF 以使标头字段占用多行。

想法?

See RFC 2822, section 2.1.1 and 2.2.3 to start

Does System.Net.Mail.MailMessage auto fold its header fields if their content exceeds the maximum length restrictions? RFC2822 states that a header field must not exceed 998 characters per line. To get around that, CRLF may be inserted to have a header field take up more than one line.

Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2024-09-22 19:16:27

MailMessage 类至少在使用 SmtpClient 发送之前不会执行任何自动折叠。仅当发送消息时,.NET 才会执行标头字段的自动折叠,以构造 MIME 消息。您可以在邮件发送后通过访问 MailMessage.Headers 进行检查。

折叠可能发生在多个位置,具体取决于头字段是否需要预先编码。例如,如果主题包含非 US-ASCII 字符,则必须使用 Base64 或 Q 编码进行编码。在这种情况下,负责编码的类也会进行折叠。

如果您使用 Reflector,您可以查看 MailWriter 类,它是执行折叠的类之一,并且至少在 .NET 2.0 中使用建议的默认行限制 78 个字符RFC2822 中指定的每行。

每行字符必须是 no
超过 998 个字符,并且应该
不超过 78 个字符

不包括 CRLF。

The MailMessage class does not do any automatic folding at least until it's sent using an SmtpClient. It's only when the message is sent that .NET performs automatic folding of the header fields in order to construct the MIME message. You can check this by accessing MailMessage.Headers after the message is sent.

The folding may occur at several places depending if the header field needs to be previously encoded. For example if the subject contains non US-ASCII characters it must be encoded in Base64 or Q encoding. In this case the classes responsible for the encoding also do the folding.

If you use Reflector you can take a look for example at the MailWriter class which is one of the classes that performs folding and that, at least in .NET 2.0, uses the recommended default line limit of 78 characters per line as specified in RFC2822.

Each line of characters MUST be no
more than 998 characters, and SHOULD
be no more than 78 characters
,
excluding the CRLF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文