Pandas send email containing dataframe as a visual table


  • Using str.format to append your DF html to the email body html.


from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
import smtplib
import sys

recipients = ['[email protected]'] 
emaillist = [elem.strip().split(',') for elem in recipients]
msg = MIMEMultipart()
msg['Subject'] = "Your Subject"
msg['From'] = '[email protected]'

html = """\

part1 = MIMEText(html, 'html')

server = smtplib.SMTP('', 587)
server.sendmail(msg['From'], emaillist , msg.as_string())

Leave a Comment