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

时间:2012-02-13 20:53:25

标签: python mime mime-message

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

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

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

我发现的一件事是它被切断的长度是标题标题及其值的组合。因此,当我将“某些标题”缩短为“某些”时,行返回更改为“原因”而不是之前。

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

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

这是正确的行为,它是执行此操作的email包(以及大部分电子邮件生成代码。)RFC822消息(以及该标准的所有后续版本)都有一种继续标题的方式所以他们不必是一条线。像这样折叠标题被认为是一种很好的做法,并且缩进标题主体其余部分的标签字符意味着标题会继续。

相关问题