How to get line breaks in e-mail sent using Python's smtplib?
问题 I have written a script that writes a message to a text file and also sends it as an email. Everything goes well, except the email finally appears to be all in one line. I add line breaks by \n and it works for the text file but not for the email. Do you know what could be the possible reason? Here's my code: import smtplib, sys import traceback def send_error(sender, recipient, headers, body): SMTP_SERVER = 'smtp.gmail.com' SMTP_PORT = 587 session = smtplib.SMTP('smtp.gmail.com', 587)