gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:16:06 27 4
gpt4 key购买 nike

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

例如

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'] 打印:-

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

打印消息打印:-

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

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

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

有什么想法吗?

最佳答案

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

关于python - 使用 email.mime 时电子邮件标题中不需要的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9267848/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com