【问题标题】:HTML: text colour in automatic generated email with pythonHTML:使用python自动生成的电子邮件中的文本颜色
【发布时间】:2019-06-16 09:23:29
【问题描述】:

我使用 smtplib 生成了一些 python 代码来发送自动电子邮件。一切正常,但是当我发送电子邮件时,文本和 html 版本的正文有时会随机将颜色更改为紫色。有没有办法确保它总是黑色(或其他颜色)?非常感谢!!!

        text = """\
        Dear Dr """ + name + """,
        How are you?
        the budget is ready:
        """
        html = """\
        <html>
          <body>
            <p style="color: black;">Dear Dr """ + name + """,<br>
               How are you?<br>
               <a href="http://www.example.com">xxx</a> 
               has many great info.
            </p>
          </body>
        </html>
        """

        # Turn these into plain/html MIMEText objects
        part1 = MIMEText(text, "plain")
        part2 = MIMEText(html, "html")


        # Add HTML/plain-text parts to MIMEMultipart message
        # The email client will try to render the last part first
        message.attach(part1)
        message.attach(part2)

【问题讨论】:

  • 您应该尝试找出这种紫色的来源。您发布的代码中似乎没有它的来源。什么样的电子邮件客户端?有没有view-source选项(雷鸟在CTRL+U下有选项)
  • 这是 gmail 收件人在文本和 html 版本中获得紫色,,,,不确定其他颜色
  • 谷歌gmail text color purple 说:support.google.com/mail/thread/3819889?hl=en

标签: python colors smtplib


【解决方案1】:

对于遇到此问题的其他人,Gmail 会将来自同一发件人的电子邮件归为一组,并会以紫色突出显示该组中先前电子邮件中相同的行。这是 Gmail 的一项功能,而不是编码错误。删除组中所有以前的电子邮件并再次发送以查看颜色变回。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-29
    • 2017-08-08
    • 2011-01-29
    • 2019-09-15
    • 2014-10-24
    • 2023-03-15
    • 1970-01-01
    • 2013-06-03
    相关资源
    最近更新 更多