.Net MailMessage 自动折叠标头字段是否超过 RFC2822 最大长度?
请参阅 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MailMessage
类至少在使用SmtpClient
发送之前不会执行任何自动折叠。仅当发送消息时,.NET 才会执行标头字段的自动折叠,以构造 MIME 消息。您可以在邮件发送后通过访问MailMessage.Headers
进行检查。折叠可能发生在多个位置,具体取决于头字段是否需要预先编码。例如,如果主题包含非 US-ASCII 字符,则必须使用 Base64 或 Q 编码进行编码。在这种情况下,负责编码的类也会进行折叠。
如果您使用 Reflector,您可以查看
MailWriter
类,它是执行折叠的类之一,并且至少在 .NET 2.0 中使用建议的默认行限制 78 个字符RFC2822 中指定的每行。The
MailMessage
class does not do any automatic folding at least until it's sent using anSmtpClient
. 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 accessingMailMessage.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.