I am trying to write the contents of a csv to the body of an email and of course having issues.
I can list out the contents as such. But looking for a formatted HTML version that I can place in the body of an email...I have been through a dozen of forums and cant seem to find a simple solution and one that works..
delimiter = ',',
quotechar = '"',
doublequote = True,
skipinitialspace = True,
lineterminator = '\r\n',
quoting = csv.QUOTE_MINIMAL)
print("\n Now the output from a dictionary created from the csv file")
with open('z_outFileRegion1.csv', 'rb') as mycsvfile:
dictofdata = csv.DictReader(mycsvfile, dialect='mydialect')
for row in dictofdata:
print(row['region']+"\t "+row['county']+"\t "+row['ramp'])
I tried this one but cant get it to work
Anyone have any easy solution to grab the CSV, format with HTML and attach it to the body of the email?
Below I am attaching the csv to the email but want to display the records in the email itself.
filename = "z_outFileRegion1.csv"
f = file(filename)
msg = MIMEMultipart()
#body = "This is the message"
#content = MIMEText(body, 'plain')
attachment = MIMEText(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
msg['Subject'] = "Region Report " + CurrentDate
server = smtplib.SMTP('smtp1.fff',25)
server.sendmail(FROMADDR, TOADDRS, msg.as_string())
getMsgP = msgEmail()