HTML 在浏览器中呈现良好但在电子邮件中呈现不佳(HTML 是使用 pandas 数据帧生成的)

HTML renders fine in browser but not in email (HTML is generated using pandas dataframe)

我正在尝试使用 pandas 数据帧在 python 中发送自动电子邮件(包含 tabled)。当我为 table 生成 HTML 并用浏览器打开它时,一切正常。当我尝试在电子邮件中呈现相同的 html 时,一些数据丢失了。

HTML 在浏览器中呈现

HTML 在电子邮件中呈现

这是我用来创建 HTML -

的代码
def csvToJinjaHTML(csvContent):

    print("Pandas: Set the max_colwidth to -1 for unlimited string length")
    pd.set_option("display.max_colwidth",-1)

    print("Pandas: Create a Pandas table from CSV content")
    pandasTable = pd.read_csv(StringIO(csvContent), index_col=False)

    # pandasTable is the dataframe that we want to beautify
    print(pandasTable)

    stylerObject = pandasTable.style

    styledHTML = (stylerObject
        .set_table_attributes('border="1" class="dataframe table table-hover table-bordered"')
        .set_properties(**{'font-size': '16pt', 'font-family': 'Calibri'})
        # .set_properties(subset=['6', '5'], **{'width': '300px'})
        .applymap(colour, subset=['ORGANIZATION'])
        .set_precision(3)
        .set_table_styles(
            [{'selector': 'tr:nth-of-type(odd)',
            'props': [('background', '#eee')]}, 
            {'selector': 'tr:nth-of-type(even)',
            'props': [('background', 'white')]},
            {'selector': 'th',
            'props': [('background', '#606060'), 
                        ('color', 'white'),
                        ('font-family', 'verdana')]},
            {'selector': 'td',
            'props': [('font-family', 'verdana')]},
            ]
        ).hide_index()
        .render()
    )

    with open('myJinjaTable.html', 'w') as f:
        print("Writing an HTML file to view the beautified Jinja table")
        f.write(styledHTML)

    return styledHTML

想通了。 HREF 链接的长度显然太长了。我减小了链接的大小,它按预期呈现。