title: How to get line breaks in e-mail sent using Python's smtplib?
body: <p>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. </p>
  
  <p>I add line breaks by <code>\n</code> and it works for the text file but not for the email. 
  Do you know what could be the possible reason?</p>
  
  <hr>
  
  <p>Here's my code:</p>
  
  <pre><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)
      session.ehlo()
      session.starttls()
      session.ehlo
      session.login(sender, 'my password')
      send_it = session.sendmail(sender, recipient, headers + "\r\n\r\n" +  body)
      session.quit()
      return send_it
  
  
  SMTP_SERVER = 'smtp.gmail.com'
  SMTP_PORT = 587
  sender = 'sender_id@gmail.com'
  recipient = 'recipient_id@yahoo.com'
  subject = 'report'
  body = "Dear Student, \n Please send your report\n Thank you for your attention"
  open('student.txt', 'w').write(body) 
  
  headers = ["From: " + sender,
                 "Subject: " + subject,
                 "To: " + recipient,
                 "MIME-Version: 1.0",
                 "Content-Type: text/html"]
  headers = "\r\n".join(headers)
  send_error(sender, recipient, headers, body)
  </code></pre>