Javascript 如何在python电子邮件正文中添加多个数据帧
我想在我的邮件正文中插入两个数据框,我可以得到一个,但不能同时得到两个 这是我的密码Javascript 如何在python电子邮件正文中添加多个数据帧,javascript,python,Javascript,Python,我想在我的邮件正文中插入两个数据框,我可以得到一个,但不能同时得到两个 这是我的密码 import smtplib import teradata import pandas as pd from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText table =[{'account': 'Jones LLC', 'Jan': 150, 'Feb': 200, 'Mar': 140},
import smtplib
import teradata
import pandas as pd
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
table =[{'account': 'Jones LLC', 'Jan': 150, 'Feb': 200, 'Mar': 140}, {'account': 'Alpha Co', 'Jan': 200, 'Feb': 210, 'Mar': 215},{'account': 'Blue Inc', 'Jan': 50, 'Feb': 90, 'Mar': 95 }]
table1 =[{'account': 'fgsdgd LLC', 'Jan': 150, 'Feb': 200, 'Mar': 140}, {'account': 'fsdgsd Co', 'Jan': 200, 'Feb': 210, 'Mar': 215},{'account': 'Blue Inc', 'Jan': 50, 'Feb': 90, 'Mar': 95 }]
sql_canc_hour = pd.DataFrame(table)
sql1 = pd.DataFrame(table1)
me = "xxx@gmail.com"
you = "xxxxxx@gmail.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Account Details"
msg['From'] = me
msg['To'] = you
# Create the body of the message (a plain-text and an HTML version).
text = " "
html = """\
<html>
<head></head>
<br>Hi Team,\n</br>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
导入smtplib
导入teradata
作为pd进口熊猫
从email.mime.multipart导入MIMEMultipart
从email.mime.text导入MIMEText
表=[{'account':'Jones LLC','Jan':150,'Feb':200,'Mar':140},{'account':'Alpha Co','Jan':200,'Feb':210,'Mar':215},{'account':'Blue Inc','Jan':50,'Feb':90,'Mar':95}]
表1=[{'account':'fgsdgd LLC','Jan':150','Feb':200','Mar':140},{'account':'fsdgsd Co','Jan':200','Feb':210','Mar':215},{'account':'Blue Inc','Jan':50',Feb':90',Mar':95}]
sql\u canc\u hour=pd.DataFrame(表)
sql1=pd.DataFrame(表1)
我=”xxx@gmail.com"
你=”xxxxxx@gmail.com"
#创建消息容器-正确的MIME类型为multipart/alternative。
msg=MIMEMultipart('alternative')
msg['Subject']=“账户详细信息”
msg['From']=我
msg['To']=您
#创建消息正文(纯文本和HTML版本)。
text=“”
html=”“”\
嗨,团队,\n
{sql\u canc\u hour}
$(“table”).addClass(“table-table-bordered-table-striped-table-responsive-table-condensed”);
"""
html1=”“”
嗨,团队,\n
{sql1}
$(“table”).addClass(“table-table-bordered-table-striped-table-responsive-table-condensed”);
"""
html=html.format(sql\u canc\u hour=sql\u canc\u hour.to\u html())
html1=html1.format(sql1=sql1.to_html())
#记录这两部分的MIME类型-text/plain和text/html。
part1=MIMEText(文本“纯”)
part2=MIMEText(html,'html')
part3=MIMEText(html1,'html')
#将部件附加到消息容器中。
#根据RFC 2046,在本例中,多部分消息的最后一部分
#HTML消息是最好的首选。
附加信息(第1部分)
附加信息(第2部分)
附加信息(第三部分)
#通过本地SMTP服务器发送邮件。
s=smtplib.SMTP('s)XXXX@gmail.com')
#sendmail函数接受3个参数:发件人地址、收件人地址
#和要发送的消息-在这里它作为一个字符串发送。
s、 sendmail(我,你,msg.as_string())
打印(“成功发送电子邮件”)
输出为
我的目标是在电子邮件正文中添加尽可能多的数据框并发送电子邮件快速查看一下,我认为您的问题不是由代码引起的,而是由于使用了两组html和head标记 某些浏览器/客户端可能无法很好地解释这一点,而只接受第一次出现。HTML文档应该只有一个集合。body标签也是如此
调整字符串以反映这一点,看看这是否解决了您的问题。Hi Benjamin,感谢您花时间阅读代码,是否可以在一个正文中添加两个数据帧,而不是创建两个部分并在结尾合并为一个。如果您有相同的语法,请告诉我
{sql_canc_hour}
<script type="text/javascript">
$("table").addClass("table table-bordered table-striped table-responsive table-condensed");
</script>
</html>"""
html1 = """ <html>
<head></head>
<br>Hi Team,\n</br>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
{sql1}
<script type="text/javascript">
$("table").addClass("table table-bordered table-striped table-responsive table-condensed");
</script> """
html= html.format(sql_canc_hour = sql_canc_hour.to_html())
html1= html1.format(sql1 = sql1.to_html())
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
part3 = MIMEText(html1, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
msg.attach(part3)
# Send the message via local SMTP server.
s = smtplib.SMTP('XXXX@gmail.com')
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
print ("Successfully sent email")