title: Sending a MySQL query as HTML in Python
body: <p>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.</p>
  
  <p>Everything runs but the email that is sent gives <code>&lt;TABLE&gt;</code> in the body.</p>
  
  <p>I used this <a href="http://www.decalage.info/python/html" rel="nofollow noreferrer">tutorial</a> and I do not see what's wrong. Please help.</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>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. </p>
  
  <p>What argument am I missing?</p>