【发布时间】: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())
对我来说看起来不错,但是一旦我运行脚本并发送邮件,它就会像纯文本一样显示,我无法点击。
我还尝试了许多其他组合删除<html> 标签,使用带有反斜杠的单引号和双引号,但没有任何效果。我什至尝试在没有Mail Helper Class 的情况下做同样的事情,但没有成功。
非常感谢您的帮助。
【问题讨论】:
标签: python email hyperlink sendgrid