【问题标题】:How to send hyperlink with SendGrid using Python如何使用 Python 使用 SendGrid 发送超链接
【发布时间】:2020-11-20 13:04:00
【问题描述】:

我正在尝试使用 SendGrid 发送一封简单的邮件,该邮件必须包含一个超链接。

我没有做任何花哨的事情,只是跟着documentation example 做了一些更改

import os
from sendgrid.helpers.mail import *

sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("test@example.com")
to_email = To("test@example.com")
subject = "Sending with SendGrid is Fun"

content = Content("text/html", '<html><a href="https://www.google.com">google</a></html>')

mail = Mail(from_email, to_email, subject, content)
response = sg.client.mail.send.post(request_body=mail.get())

对我来说看起来不错,但是一旦我运行脚本并发送邮件,它就会像纯文本一样显示,我无法点击。

我还尝试了许多其他组合删除&lt;html&gt; 标签,使用带有反斜杠的单引号和双引号,但没有任何效果。我什至尝试在没有Mail Helper Class 的情况下做同样的事情,但没有成功。

非常感谢您的帮助。

【问题讨论】:

    标签: python email hyperlink sendgrid


    【解决方案1】:
    content = Content(
    
        "text/html", "Hi User, \n This is a test email.\n This is to also check if hyperlinks work <a href='https://www.google./com'> Google </a> Regards Karthik")
    

    这对我有帮助。我相信你不需要提及html标签

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 2016-07-22
      • 2017-10-17
      • 2013-05-31
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      相关资源
      最近更新 更多