Python电子邮件正文为空

2024-06-16 13:33:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我是来请你帮忙的。在

所以问题是,我的邮件主题是好的,但当我打开邮件,它是空的,我真的不明白为什么。。。在

这是我的代码:

from urllib2 import urlopen
import smtplib
s=smtplib.SMTP('smtp.gmail.com',587)
s.starttls()
s.ehlo()

# now login as my gmail user
username='myEmail@gmail.com'
password='*****************'
s.login(username,password)

# the email objects and body
replyto='myEmail@gmail.com'
sendto=['myEmail@gmail.com']
subject='Mail automatisation'
content="This is a test"
mailtext='Subject:'+subject+'\n'+content

# send the email
s.sendmail(replyto, sendto, mailtext)

rslt=s.quit()

谢谢你的帮助。在


Tags: theimportcomemailusername邮件loginpassword
1条回答
网友
1楼 · 发布于 2024-06-16 13:33:36

因特网消息格式的定义需要在头部分和正文之间有一个空行。由于您有一个正确的标题(subject),空行之前的所有内容都可能被解释为可能不正确的标题。这意味着邮件读者可以选择忽略它

你只需要:

mailtext='Subject:'+Subject+'\n\n'+内容

相关问题 更多 >