0

I'm working on an app that sends out emails. I would like to be able to embed a custom generated table into the email body. However, it is rendered as text instead of parsed as html and displayed accordingly. I am using HTML.py to create a table using a list, and emailing it. Any ideas whats going on? I'm using requests to send the email, so SMTP and mailers wont be of much help to me.

<TABLE cellpadding="4" style="border: 1px solid #000000; border-collapse: collapse;" border="1">
 <TR>
  <TD>Apple (Ammre)</TD>
  <TD>53.0</TD>
  <TD>55.0</TD>
 </TR>
</TABLE>

This is the table generated by HTML.py. I append the <html> tag around it. But to no avail. Any advice would be much appreciated.

This is how I'm generating the HTML from python.

for fruit in fruits:
    fruitPrices.append([fruit.name, fruit.price_min, fruit.price_max])

htmlcode = "<HTML>" + HTML.table(fruitPrices) + "</HTML>"
print htmlcode

and sending like this

requests.post(
    "URL HERE",
    auth=("api", "MY KEY HERE"),
    data={"from": "MY EMAIL ADDRESS HERE",
          "to": email,
          "subject": subject,
          "text": message
          })
Irtza.QC
  • 1,026
  • 2
  • 10
  • 23
  • 4
    check this answer http://stackoverflow.com/questions/882712/sending-html-email-using-python – pregmatch Oct 19 '15 at 10:03
  • Im using Mailgun and request.posts to send the email? Im not using SMTP so would that answer still apply? – Irtza.QC Oct 19 '15 at 10:13
  • It's still (mostly) applicable, because it shows you what content you need, and how to organize it (eg put the HTML part last). – PM 2Ring Oct 19 '15 at 10:18
  • i can only assume you are missing something like -F html='My awesome newsletter'. It would be great if you paste your python code so we can see what you are missing. – pregmatch Oct 19 '15 at 10:33
  • ive added the python code. id be eternally grateful if you spot the darned error. – Irtza.QC Oct 19 '15 at 10:40
  • Take a look at [this answer](http://stackoverflow.com/a/15763629/4014959). Note that you need to use `MIMEMultipart('alternative')` rather than `MIMEMultipart('related')` – PM 2Ring Oct 19 '15 at 10:50

0 Answers0