Reputation:
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='[email protected]'
password='*****************'
s.login(username,password)
# the email objects and body
replyto='[email protected]'
sendto=['[email protected]']
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.
Upvotes: 2
Views: 2411
Reputation: 149155
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
Upvotes: 6