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=""></script>
      <link rel="stylesheet" href="">
      <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'] = ''
msg['To'] = ''
msg.attach(MIMEText(html_string, 'html', 'utf-8'))

s = smtplib.SMTP('', 587)

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


1 Like

Same problem. @zen100 did you solve it?