如何在邮件正文中显示数据帧和JNG ?



我试图在mailbody中发送带有JNG (fng_image.jpg)和dataframe (email_table.html)的自动邮件数据框已经转换为html文件(email_table.html)

然而,我挣扎与MIMEText代码…我下面的代码返回一个电子邮件,只有数据帧覆盖其余的

msgRoot = MIMEMultipart('related')
msgRoot['From'] = Header("Crypto-Ccy",'utf-8')
msgRoot['To'] =  Header("Guests",'utf-8')
subject = 'Crypto Fear & Greed Index'
msgRoot['Subject'] = Header(subject,'utf-8')

msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
fp = open('fng_image.jpg','rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgRoot.attach(msgImage)
html = open("email_table.html")
msgRoot = MIMEText(html.read(),'html')

谢谢,那么我如何同时发送嵌入图片和数据帧呢?

msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgText = MIMEText('<br><img src="cid:image1"><br>', 'html')
msgAlternative.attach(msgText)
fp = open('fng_image.jpg', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage)
html_tab = open("email_table.html")
msgRoot.attach = MIMEText(html_tab.read(), 'html')

最新更新