python - 如何使用 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 Class的情况下做同样的事情,但它没有用。
非常感谢您的帮助。
解决方案
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标签
推荐阅读
- python - 如何在 Python 中禁用 chromedriver“Chrome 正在由自动测试软件控制”通知?
- reactjs - 反应 useEffect 和 setInterval
- reactjs - 使用 docker-compose 的 ASP.NET Core 5.0 React app npm 错误
- security - 我的身份验证流程是否安全/最佳实践?
- python - 从 Jenkins 收集所有日志到 excel 文件
- python - 如何使用线程加速读取 zip 文件
- numpy - Numpy vs Eigen vs Xtensor 线性代数基准奇数
- scala - org.specs2.specification.core.AsExecution[scala.util.Try[org.specs2.matcher.MatchResult[String]]] 类型的证据参数的 specs2 隐式值
- yosys - 如何获取使用门而不是 LUT 的 .bench 文件
- python - venv 从哪里得到点子?