I'm working on an automated email sender script. My goal is to send 2 tables by email each and every time my results are generated. So far I tried the tabulate python package, which looks really nice if I print it in the console of PyCharm, but when I send this format by email, the look breaks apart.
For this I used a method found here: Send table as an email body (not attachment ) in Python
My aim is to achive a similar table in outlook, like in pycharm. What I noticed is that the rows of data is being split when it appears in outlook.
UPDATE:
Here is the code I have tryed:
import pandas as pd
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sample_df = pd.read_csv("sampleqc.txt", sep="\t")
sample_df = sample_df.to_html(table_id='SAMPLEQC', index=False)
sample_df = sample_df.replace('class="dataframe" id="SAMPLEQC">', 'class="styled-table" id="SAMPLEQC">')
with open("table_style.txt") as style:
table_style_html = style.read()
final_html = "<html><body>" + table_style_html + sample_df + "</body></html>"
me = 'mymail@gmail.com'
password = 'password'
server = 'smtp.gmail.com:587'
you = 'custom@domain.mail'
message = MIMEMultipart("alternative")
message['Subject'] = "Your data"
message['From'] = me
message['To'] = you2
html_body = MIMEText(final_html, 'html')
message.attach(html_body)
server = smtplib.SMTP(server)
server.ehlo()
server.starttls()
server.login(me, password)
server.sendmail(me, you2, message.as_string())
server.quit()
I tried to use it to send email to Gmail which look like this:
and the same code in Microsoft Outlook:
Any idea how can I manage this problem? Thanks in advance!