'how can I display a dataframe and JNG in email body?

I am trying to send a automated mail with a JNG (fng_image.jpg) and dataframe (email_table.html) in mailbody The dataframe is already converted into a html file (email_table.html)

However, am struggling with MIMEText codes...my below coding returns a email with only the dataframe overriding the rest

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')


Solution 1:[1]

Thanks, so how can I send embed both picture and a dataframe at same time?

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')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DereKwan