I have quickly written below code to send data being sent to REST remote server for debuging but I am receiving blank email. now sure what is going wrong . in the terminal body dict text or json converted text is getting printed but getting nothing in email.
# For testing
def sendMail(usr, pwd, to, body):
""" just for testing to send error via email
"""
fromaddr = usr
toaddr = to
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Data add request"
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(usr, pwd)
msg.attach(body)
r = json.dumps(body)
loaded_r = json.loads(r)
print "json: ", str(loaded_r)
server.sendmail("error-report@do_not_reply.com", to, str(loaded_r))
except Exception, err:
print 'Error sending email: ', err
finally:
server.quit()
I tried sending server.sendmail("error-report@do_not_reply.com", to, body) but that too sends blank email without subject. what am I doing wrong ?