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