python电子邮件,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...

Here is my code :

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

Thanks for you help.

解决方案

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

You just need:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值