Reputation: 1511
I want to send an email through python, I followed the below code from this link:
import smtplib
mailserver = smtplib.SMTP('smtp.office365.com',587)
mailserver.ehlo()
mailserver.starttls()
mailserver.login('[email protected]', 'mypassword')
msg = ('this is a message')
mailserver.sendmail('[email protected]','[email protected]',msg)
The issue: The email is in my sentbox, and the receiver's inbox, however there is no text. It is empty.
There is no error, or output, the script just runs, so I am unsure where to start troubleshooting, as I am not an expert in this area; could anyone explain why there is no message/text?
Upvotes: 1
Views: 414
Reputation: 913
You need a \n
between subject and email body in the 3rd argument to sendmail
msg = 'Subject: Email Subject.\n{}'.format('this is a message')
mailserver.sendmail('[email protected]','[email protected]', msg)
Upvotes: 2