使用 email.mime 时电子邮件标题中不需要的换行符

发布于 2025-01-05 00:10:03 字数 854 浏览 1 评论 0原文

我正在使用 SMTP 并使用 email.mime 来提供标头结构。由于某种原因,当尝试添加超过一定长度的标题时,换行符会添加到我的标题行中。

例如

from email.mime.text import MIMEText
message = 'some message'
msg = MIMEText(message)
msg.add_header('some header', 'just wondering why this sentence is continually cut in half for a reason I can not find')

print msg['some header']
print msg

print msg['some header'] prints:-

some header: just wondering just wondering why this sentence is continually cut in half for a reason I can not find

print msg prints:-

some header: just wondering why this sentence is continually cut in half for a
 reason I can not find

我确实发现的一件事是它被截断的长度是标题标题及其值的组合。因此,当我将“some header”短路为“some”时,行返回更改为“reason”之后而不是之前。

这不仅仅是我的查看页面宽度:),它实际上会发送电子邮件标题中带有换行符的电子邮件。

有什么想法吗?

I'm playing around with SMTP and using email.mime to provide the header structure. For some reason when a try to add a header that exceeds a certain length a line break is added into my header line.

e.g.

from email.mime.text import MIMEText
message = 'some message'
msg = MIMEText(message)
msg.add_header('some header', 'just wondering why this sentence is continually cut in half for a reason I can not find')

print msg['some header']
print msg

print msg['some header'] prints:-

some header: just wondering just wondering why this sentence is continually cut in half for a reason I can not find

print msg prints:-

some header: just wondering why this sentence is continually cut in half for a
 reason I can not find

One thing I did discover is that the length at which it's cut off is a combination of the header title and its value. So when I shorted 'some header' to 'some', the line return changes to after 'reason' instead of before.

It's not just my viewing page width :), it actually sends the email with the new line character in the email header.

Any thoughts?

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

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

发布评论

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

评论(1

美人迟暮 2025-01-12 00:10:03

这是正确的行为,并且是 email 包执行此操作(以及大多数电子邮件生成代码)。RFC822 消息(以及该标准的所有后继者)有一种连续标头的方法所以它们不必是一行。像这样折叠标题被认为是很好的做法,并且缩进标题正文其余部分的制表符意味着标题是继续的。

This is correct behaviour, and it's the email package that does this (as well as most of the email generating code out there.) RFC822 messages (and all successors to that standard) have a way of continuing headers so they don't have to be a single line. It's considered good practice to fold headers like that, and the tab character that indents the rest of the header's body means the header is continued.

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