The following piece of code is formatting my email script correctly. It is placing the to, from, subject, and body in the correct parts of the email. My problem is that I can’t figure out why it needs two returns and two newlines (“\r\n\r\n”) in my connect function to display the body in the email when the rest of the headers only need one CR.
def message(self):
subject = input("What is the subject line of your message")
headers = ["from: " + self.sendfrom,
"to: " + self.sendto,
"subject: " + subject,
"content_type: text/html"]
headers = "\r\n".join(headers)
msg = input("type your message")
return headers, msg
def connect(self, headers, msg):
self.server.starttls()
self.server.login(self.usrname,self.pswd)
self.server.sendmail(self.sendfrom, self.sendto, headers + "\r\n\r\n" + msg)
print("I sent the email")
return self.server
Thanks!
Because of the standard, body must be separated from the headers with an empty line.
e-mail software conforms to these standards and expects an empty line for the body. If there is no empty line, it just assumes the text is part of headers, and usually these email softwares hide most headers by default.