Home > Mobile >  How do I neatly format an email body using python?
How do I neatly format an email body using python?

Time:12-08

I have the code below:

import smtplib
from config import Parameters
def send_email_issues(issues_found):
    issues_found="Hello All, \nThe following columns are missing in ARCM source (Mikes Data) : sdfsdfds, 1, 2, 45rgvdfgzfb \n Found new Frequency in Monitor AU Frequency : Supplemental, These columns are missing in exceptions file :Reg Impact >= Reg Tier "
    HOST = "localhost"
    SUBJECT = "AR Issues Foud"
    TO = "[email protected]"
    FROM = "[email protected]"
    text = "The following Issues were found for  " Paramdate  ":"  "/n"
    BODY = "\r\n".join((
    "From: %s" % FROM,
    "To: %s" % TO,
    "Subject: %s" % SUBJECT ,
    "",
    issues_found
    ))
    server = smtplib.SMTP(HOST)
    server.sendmail(FROM, [TO], BODY)
    server.quit()

Currently I am getting the entire string as a single line. How do I turn it into something resembling the below?

Hello All,

The following issues were found :
The following columns are missing in ARC : sdfsdfds, 1, 2, 45rgvdfgzfb \n
Found new Frequency in Monitquency : Supemental, 
These columns are missing in exceptions file :Reg Impact >= Re

Thankyou
Team

i.e. on separate lines?

CodePudding user response:

Is your Content-Type text/html, or text/plain? If your content type is text/html, you should be using <br> for line breaks instead of \n.

  • Related