title: Send result of query in email body using python
body: <p>Essentially I'm trying to send the results of a query in the body of an email and can't figure it out. I tested the code for the SQL query and it works independently. I also can send an email no problem. Having trouble putting them both together. I then tried converting the result of the query into a string but that's not working. Here is my code: </p>
  
  <pre><code>import smtplib
  import pyodbc
  import pandas as pd
  
  cnxn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
                        r"DBQ=\\Location.accdb;")
  
  query = """SELECT *;
          """
  
  df = pd.read_sql(query, cnxn)
  
  remail = "sendto@gmail.com"
  
  smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
  smtpObj.ehlo()
  smtpObj.starttls()
  
  smtpObj.login('from@gmail.com','PASSWORD')
  
  smtpObj.sendmail('from@gmail.com', remail, 'Subject: Latest Query \n' + string(df))
  
  smtpObj.quit()'
  </code></pre>
  
  <p>Any ideas? </p>