【问题标题】:HTML tables not opening in Outlook (pd.to_html)HTML 表格未在 Outlook 中打开 (pd.to_html)
【发布时间】:2019-10-12 13:48:25
【问题描述】:

我正在使用 pd.to_html 通过电子邮件发送我的 pandas 数据帧,电子邮件在 Gmail 浏览器中打开正常,所有表格都在电子邮件正文中。但是它们并没有在 Outlook 中打开所有表格都在 Outlook 中作为 HTML 附件。

使用以下代码将我的数据框转换为 HTML。

df_1 = df_1.to_html(index=False,header= True,border=4,justify = 'left',col_space =9)

从 IPython.core.display 导入显示,HTML 显示(HTML(df_1))

这就是我发送电子邮件的方式:-

    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from email.mime.base import MIMEBase
    from email import encoders

    email_user = 'xyz@x.com'
    email_password = '*********'
    email_send = 'xyz@x.com'
    subject = 'ABCDEF'
    msg = MIMEMultipart()
    msg['From'] = email_user
    msg['To'] = email_send
    msg['Subject'] = subject


    body_1 = """ Hey All,

    Please find the data:

    """
    msg.attach(MIMEText(body_1,'plain'))
    msg.attach(MIMEText(df_1,'html'))

    text = msg.as_string()
    server = smtplib.SMTP('smtp.gmail.com',587)
    server.starttls()
    server.login(email_user,email_password)

    server.sendmail(email_user,email_send.split(','),text)
    server.quit()

没有错误的电子邮件在 Gmail 中正确打开。但在 Outlook 中,表格是作为附件提供的。

【问题讨论】:

  • 我们需要看看您是如何发送/创建电子邮件的。
  • 嘿,Rich,我已经编辑了 Q 的更多细节,请检查并让我知道是否有相同的解决方案。

标签: python html python-3.x email outlook


【解决方案1】:

您可以将单个附件制作为 html。这对我有用。

df_1 = df_1.to_html(index=False,header= True,border=4,justify = 'left',col_space =9)

mailBody= """<p> Hi All, <br><br>

Please find the data: </p> <br><br>
""" + df_1 + """<br> Thanks. """

msg.attach(MIMEText(mailBody,'html'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多