我能够创建两个dataframe列表并将它们转换为html,但我想知道如何按顺序包含它们,以便它们填充我每天打算发送的电子邮件。我已经在这篇文章中更新了我的代码和问题。对于每个{0]、{1}等,我想插入一个 Dataframe 。可能吗?
import datetime
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import pandas as pd
import matplotlib
ALL_DFS = [L_MUNIC_s, L_MUNIF_s, L_CAMNY_s, L_NYMNY_s]
ALL_DFS_html= ''
for ALL_DF in ALL_DFS:
ALL_DFS_html += ALL_DF.render()
ALL_DFS2 = [L_MUNIC_NAV, L_MUNIF_NAV, L_MUNIC5, L_MUNIF5]
ALL_DFS_html2= ''
for ALL_DF2 in ALL_DFS2:
ALL_DFS_html2 += ALL_DF2.to_html()
def send_mail():
dataf1 = ALL_DF
dataf2 = ALL_DF2
sender = "<name>@gmail.com"
receiver = ['<name>@gmail.com']
msg = MIMEMultipart('related')
today = datetime.date.today()
msg['Subject'] = "Daily Email " +
str(today.strftime("%m/%d/%y"))
msg['From'] = sender
msg['To'] = ", ".join(receiver)
html = """\
<html>
<head></head>
<body>
<p>Good Morning Team!<br>
L-MUC
NET ASK: {0}
Exposure:<br>
{1}
<br>Top 5:<br>
{2}
<br>
<br>NEW:<br>
{3}
<br>
</p>
<p>
L-MUF
NET ASK: {4}
Exposure:<br>
{5}
<br>Top 5:<br>
{6}
<br>
<br>NEW:<br>
{7}
<br>
</p>
<p>
L-CAY
NEW ASK: {8}
Exposure:<br>
{9}
<br>NEW:<br>
{10}
<br>
</p>
<p>
L-NYY
NEW ASK: {11}
Exposure:<br>
{12}
<br>NEW:<br>
{13}
<br>
</p>
</body>
</html>
""".format(dataf1.render(), dataf2.to_html())
partHTML = MIMEText(html, 'html')
msg.attach(partHTML)
ser = smtplib.SMTP('gateway_server', port_number)
ser.login("username", "password")
ser.sendmail(sender, receiver, msg.as_string())
return send_mail()
1条答案
按热度按时间eeq64g8w1#
如果评论中提供的链接不能回答您的问题,我想知道这是否可以解决您的问题。