1

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('myemail@company.com', 'mypassword')
msg = ('this is a message')
mailserver.sendmail('myemail@company.com','receiver@company.com',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?

Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60

1 Answers1

2

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('myemail@company.com','receiver@company.com', msg)
kudeh
  • 883
  • 1
  • 5
  • 16