I have a piece of code where I am running a MySql query in python. I then return the query as an HTML file which is emailed.
Everything runs but the email that is sent gives <TABLE>
in the body.
I used this tutorial and I do not see what's wrong. Please help.
import pymysql
import os
import HTML
conn = pymysql.connect(host='localhost', port=1000, user='users', passwd='pw', db='database')
cur = conn.cursor()
#mysql query
query = ("""select * from table""")
cur.execute(query)
rows = cur.fetchall()
for row in rows:
for col in row:
print "%s," % col
print "\n"
htmlcode = HTML.table(rows)
print htmlcode
import smtplib
content = 'email report'
mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.ehlo()
mail.starttls()
mail.login('email@email.com', 'pw')
mail.sendmail('email@email.com', 'email@email.com', htmlcode)
mail.close()
When I go to the email message I can see the original text and the HTML query is there, just not showing up in the body of the email.
What argument am I missing?