I’m using sendmail on one of my servers to send out error reports. I’m building this report by appending to a string and then I use sendmail to send the email. However, sendmail does not recognize the tabs in the string. I’m wondering how do I fix this?
def sendMail(data):
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % sendmail_location, "w")
p.write("From: %s\n" % "test@example.com")
p.write("To: %s\n" % "test2@example.com")
p.write("Subject: the subject\n")
p.write(data)
status = p.close()
if status != 0:
print "Sendmail exit status", status
An example string would be:
data = "%d\t%s\t%s\n" % (count, message, message2)
the way things look at the moment, that line is being treated as a header. you need a blank line after the headers: