I am trying to send an excel table in the body of an email that is accompanied by some text
This is what I’ve tried:
import pandas as pd
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart('alternative')
msg['Subject'] = "Lists"
msg['From'] = sender_email
msg['To'] = receiver_email
html = html_file
text = "Hi,n Please find attached the relevant datan"
msg.attach(MIMEText(text, 'plain'))
msg.attach(MIMEText(html, 'html'))
s = smtplib.SMTP('smtp.gmail.com',587)
s.connect('smtp.gmail.com',587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(sender_email, password)
print("login success")
s.sendmail(sender_email, receiver_email, msg.as_string())
print("email has been sent")
s.quit()
Currently this is sending out the table as required, however the “Hi,n Please find attached the relevant datan” text is not being added to the email.
Any help would be great!