如何使用Python通过SendGrid发送超链接



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

我没有做任何花哨的事情,只是按照文档示例进行了一些更改

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())

对我来说,这看起来很好,但一旦我运行了脚本并发送了邮件,它就会显示为我无法点击的纯文本。

我还尝试了许多其他组合来删除<html>标记,使用带反斜杠的单引号和双引号,但没有真正奏效。我甚至试着在没有Mail Helper类的情况下做同样的事情,但没有成功。

非常感谢你的帮助。

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标签

最新更新