Home > Software engineering >  Inserting Dataframe into Outlook email message
Inserting Dataframe into Outlook email message

Time:06-23

I'm trying to insert a dataframe into an email and tried using pretty html tables and to_html. The email displays and everything looks great except the table is not embedded. I've tried several methods but nothing seems to work. Any thoughts? Code below. (And thanks in advance!)

    import win32com.client as client
    from pretty_html_table import build_table
    outlook = client.Dispatch('Outlook.Application')
    message = outlook.CreateItem(0)
    message.Display()
    message.To = "EMAIL"
    message.Subject = "Action Required - XXXX"
    html_body = """

    HTML CODE HERE

    """.format(build_table(df_final, 'blue_light'))

    message.HTMLBody = html_body

CodePudding user response:

This is how I was able to embed a pretty table into an e-mail

table_checked = build_table(<Your DF>, 'blue_dark', width = 'auto')

body = f"""
<html>
<head>
</head>

<body>
    <p>Team,<br />
    <br />
    Blah Blah Blah</b>.
    {table_checked}
    blah blah blah<br />
    <br />
    Respecfully,<br />
    <Your Name> <br />
    <br />
    <b>end of the email</b></p>
</body>

</html>
"""
  • Related