For the purpose of having embedded interactive graphs, I am trying to use plotly -> html -> MIME (python). However, the email is merely attaching a file or coming up as blank. The commented out permutations lead to failure as well. All and any help greatly appreciated.
msg = MIMEMultipart()
t1=datetime.now()
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("me@gmail.com", "password")
import plotly
import plotly.express as px
from plotly.offline import plot
import plotly
import plotly.express as px
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from smtplib import SMTP
import smtplib
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
#x=plotly.io.to_html(fig, include_plotlyjs=False, full_html=False)
#div = plot(fig,output_type = 'div',include_plotlyjs = True)
div3 = plotly.offline.plot({"data": [go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],"layout": go.Layout(title="hello world")}, include_plotlyjs=True, output_type='div')
part1 = MIMEText(div3,'html','utf-8')
#part1 = MIMEText(div3)
msg.attach(part1)
s.sendmail('me@gmail.com','to@gmail.com', msg.as_string())
s.quit()
I referenced How can I send a plot.ly image inline of an html email using smtp?, python send plotly chart (div) as email content