Outlook Desktop呈现HTML表错误

时间:2019-04-30 15:13:33

标签: python outlook office365 ms-office html-email

我有一个Python应用程序,可以发送HTML格式的电子邮件。该电子邮件仅包含12个带有最简单HTML代码的html表。但是,每个电子邮件中都有一些格式错误。选中屏幕快照中的红色框enter image description here。我确定HTML代码是有效的。如何解决该问题?

[更新]第二张图片与Firefox中的HTML代码相同。我正在使用Microsoft Office 365桌面。

 try:
        sender = ercot_config.getProperty('SMTP_SENDER')
        to = ercot_config.getProperty('TARGET_EMAIL')


        msg = MIMEMultipart()
        msg['Subject'] = title

        body = """
        <html>
        <head>
        <style>
            td {
                    min-width: 100px;
                    width: 100px;
                    border:solid lightgrey 1.0pt;
                    border-left:none;                
                    padding:3.75pt 3.75pt 3.75pt 3.75pt;
                    text-align:left;
            }
            th {
            background:#00285e;
                min-height: 20px;
                height: 20px;
                }
                h3 {
                font-size:14.0pt;
                font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;
                color:#555555
                    }

            .td-profit{
                color: #33cc33;
            }
            .td-loss {
                color: #e60000;
            }
            .tr-total {
                background-color: #f1f1f1;
                font-weight: 600

            }
            .place-holder {
                margin-top: 15px
            }

        </style>
        </head>

        <body>
        %s
        </body>
        </html>

        """ % htmlBody

        part2 = MIMEText(body, 'html')
        msg.attach(part2)

        s = smtplib.SMTP(ercot_config.getProperty('SMTP'))
        s.ehlo()
        s.starttls()
        s.login(sender, ercot_config.getProperty('SMTP_PASSWD'))

        s.sendmail(sender, to.split(","), msg.as_string())
        s.quit()

屏幕截图中第一个表格的HTML代码

<table id="t1"><tr><th colspan="26">Physical IMPORT - DC_R</th></tr><tr><th>Line Item</th><th>HE1</th><th>HE2</th><th>HE3</th><th>HE4</th><th>HE5</th><th>HE6</th><th>HE7</th><th>HE8</th><th>HE9</th><th>HE10</th><th>HE11</th><th>HE12</th><th>HE13</th><th>HE14</th><th>HE15</th><th>HE16</th><th>HE17</th><th>HE18</th><th>HE19</th><th>HE20</th><th>HE21</th><th>HE22</th><th>HE23</th><th>HE24</th><th>Total</th></tr><tr><td>MX DA Price</td><td>$39.02</td><td>$33.62</td><td>$31.08</td><td>$30.38</td><td>$30.47</td><td>$32.18</td><td>$34.93</td><td>$45.14</td><td>$22.45</td><td>$23.62</td><td>$33.79</td><td>$41.12</td><td>$45.84</td><td>$45.36</td><td>$46.55</td><td>$46.10</td><td>$46.57</td><td>$45.70</td><td>$45.74</td><td>$22.08</td><td>$51.95</td><td>$53.70</td><td>$47.47</td><td>$37.03</td><td>-</td></tr><tr><td>US RT Price</td><td>$16.43</td><td>$15.54</td><td>$14.17</td><td>$8.12</td><td>$9.56</td><td>$15.04</td><td>$16.12</td><td>$15.14</td><td>$16.65</td><td>$16.52</td><td>$17.39</td><td>$17.84</td><td>$19.16</td><td>$23.50</td><td>$34.20</td><td>$33.98</td><td>$35.99</td><td>$33.40</td><td>$29.19</td><td>$26.61</td><td>$26.65</td><td>$25.98</td><td>$21.12</td><td>$18.57</td><td>-</td></tr><tr><td>Volume</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>PnL</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>Total Costs</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>Net PnL</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr></table>

enter image description here

0 个答案:

没有答案