🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Send HTML email with embedded plotly figure


I am trying to send a Multipart email using Python where a plotly table is embedded into the HTML email content; however the table is not displaying in the email. All other content displays fine. My work around is currently to export the table as a PNG file and then read this file into the email, but I am trying to avoid exporting the table. Below is my code:

from plotly.offline import plot
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
import smtplib

plt_table = plot(table, show_link=False, include_plotlyjs=False, output_type='div')
html_string = '''
      <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
      <style>body{ margin:0 100; background:whitesmoke; }</style>
        <p>Date: '''+exr_mismatches.iloc[0,2].strftime('%Y-%m-%d')+'''</p>
        <p>Table: '''+exr_name+'''</p>
        <p>Inconsistencies: '''+str(len(exr_mismatches))+'''</p>
        '''+plt_table +'''

msg = MIMEMultipart()
msg['Subject'] = 'Report'
msg['From'] = 'sender@hotmail.co.uk'
msg['To'] = 'recipient@gmail.com'
msg.attach(MIMEText(html_string, 'html', 'utf-8'))

s = smtplib.SMTP('smtp.office365.com', 587)

Any help to get my table to appear would be much appreciated.


1 Like

Same problem. @zen100 did you solve it?