'how to display Build_table in mailbody instead of attachment?

Appreciate if someone can advise I want to send a mail with a picture ("fng_image.jpg") and dataframe ("output_table") in emailbody

However, the dataframe becomes an attachment instead Can you advise what's wrong with below codes?

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)

msgRoot.attach(MIMEText(output_table, '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