【发布时间】:2020-10-11 21:34:01
【问题描述】:
Noob,尝试使用 Python 和 Thunderbird 自动向几十个人发送不常见的个性化电子邮件(如果我必须在每封邮件上单击发送,我很好)。不幸的是,我最终在每条消息的正文中添加了以下额外的标头,我想禁止它:
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
我的代码如下:
def send_email(name, email_address):
os.system("thunderbird -compose to= 'to',subject='subject',body='body'")
tbirdPath = r'c:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe'
msg = MIMEMultipart()
msg['To'] = email_address
msg['Subject'] = 'Hello Friend'
# Body of Email - part of code with display problem (in Thunderbird)
body = "Dear {}".format(name) + '\n' + '\n' + "This is the body." + '\n' + '\n' + "The End." + '\n'
composeCommand = 'format=html,to={},subject={},body={}'.format(msg['To'], msg['Subject'], MIMEText(body))
subprocess.Popen([tbirdPath, '-compose', composeCommand])
当我打印到控制台时,我得到了我期望的正文,但是当 Thunderbird 填充时得到了额外的行/标题。从下面的第一篇文章中,看起来 get_payload 可以解决这个问题(但我不知道如何解决)。另外,在没有成功之后我搬到了 MIME,并怀疑这是我的标题的来源。 (String Formatting in Python/Thunderbird)。我可以实现的简单答案是首选。
Strange unwanted header when reading text file with MIMEText Python-Parse email Body and truncate MIME headers
【问题讨论】:
标签: windows python-3.6 thunderbird mime-message