我想發送在熊貓Python中創建的兩個數據框作爲從python腳本發送的電子郵件中的html格式。在HTML格式的Python電子郵件mimelib
我想寫一個文本和表並重復這兩個數據框,但腳本不能附加多個HTML塊。 的代碼如下:
import numpy as np
import pandas as pd
import smtplib
import time
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender = "[email protected]"
recipients = ['[email protected]']
msg = MIMEMultipart('alternative')
msg['Subject'] = "This a reminder call " + time.strftime("%c")
msg['From'] = sender
msg['To'] = ", ".join(recipients)
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttps://www.python.org"
html = df[['SYMBOL','ARBITRAGE BASIS %']].to_html()
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
username = '[email protected]'
password = 'blahblah'
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(sender, recipients, msg.as_string())
server.quit()
print("Success")
我收到一封電子郵件,剛剛過去的一部分,在電子郵件正文中格式化的HTML表格。第1部分文本沒有出現。怎麼了?
非常感謝! – Akshay