I am trying to send an email without attachement from a csv file. This csv file is a 3*9 cells +1 header row.
I want to send in this format in a nice format.
This is my code:
me = 'email'
password = 'password'
server = 'smtp.gmail.com:587'
you = 'email'
text = """
Hello, Friend.
Here is your data:
{0}
Regards,
Me"""
html = """
<html><body><p>Hello, Friend.</p>
<p>Here is your data:</p>
{0}
<p>Regards,</p>
<p>Me</p>
</body></html>
"""
with open('test.csv','r') as fin:
reader=csv.reader(fin, delimiter=',')
all_text = str()
for row in reader:
temp=list(row)
all_text+= '\n'.join(row)
text = text.format(all_text, tablefmt="grid")
html = html.format(all_text, tablefmt="html")
message = MIMEMultipart(
"alternative", None, [MIMEText(text), MIMEText(html,'html')])
message['Subject'] = "Your data"
message['From'] = me
message['To'] = you
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(me, password)
server.sendmail(me, you, message.as_string())
server.quit()
It is working, but in the email there isn't any seperator, there isn't any cells, it looks very bad and unreadable.
How can i fix the format?