Python电子邮件正文为空 [英] Python email body is empty

查看:193
本文介绍了Python电子邮件正文为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里向您寻求帮助。

I'm here to ask you some help.

问题是,我的电子邮件主题没问题,但是当我打开电子邮件时,它是空的,我真的不明白为什么...

So the thing is, the subject of my email is alright but when I open the email, it's empty and I really can't understand why...

这是我的代码:

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()

感谢您的帮助。

推荐答案

Internet邮件格式 RFC5322 (例如RFC822)在标头部分和正文之间需要有一个空行。由于您有一个正确的标题(主题),因此空行之前的所有后续操作都可以解释为可能不正确的标题。这意味着邮件阅读器可以选择忽略它

The definition of the Internet Message Format (RFC5322 ex. RFC822) requires an empty line between the headers part and the body. As you have one correct header (subject), all what follows before an empty line can be interpreted as a possibly incorrect header. That means that a mail reader can chose to ignore it

您只需要:

mailtext ='Subject: '+ subject +'\n\n'+ content

mailtext='Subject:'+subject+'\n\n'+content

这篇关于Python电子邮件正文为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆