如何告诉sendgrid停止装饰纯文本网址?
如果重要的话,使用sendgrid SDK for Python。
sendgrid.SendGridClient(username, pwd)
mail = sendgrid.Mail()
mail.set_html(html_message)
mail.set_text(text_message_with_urls) # <-- urls are here
...
sendgrid_client.send(mail)
对于HTML方面,这已有答案:
Is it possible to exclude links from tracking
邮件的HTML部分仍然需要跟踪。
答案 0 :(得分:3)
我联系了支持人员,他们通知我可以将Clicktrack SMTP filter与X-SMTPAPI
标头一起使用。
有两个过滤器选项,一个是启用和禁用点击跟踪设置,另一个是用于启用或禁用邮件“纯文本”部分中的点击跟踪链接。
Sendgrid Python客户端具有帮助程序类ClickTracking来控制这些设置:
import json
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import *
sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
from_email = Email("team@example.com")
to_email = To("test@example.com")
subject = "Sending with ClickTracking plain text disabled"
content = Content(MimeType.text, "Test URL: https://www.google.com")
message = Mail(from_email, to_email, subject, content)
tracking_settings = TrackingSettings()
tracking_settings.click_tracking = ClickTracking(enable=True, enable_text=False)
message.tracking_settings = tracking_settings
response = sendgrid_client.send(message=message)
print(response.status_code)
一个烧瓶邮件示例,该示例使用clicktrack过滤器设置“ X-SMTPAPI”标头:
from flask_mail import Mail
from flask_mail import Message
mail = Mail(app)
subject = "Sending with clicktrack plain text disabled"
body = "Test URL: https://www.google.com"
headers = {"X-SMTPAPI": json.dumps({
"filters" : {
"clicktrack" : {
"settings" : {
"enable" : 1,
"enable_text" : False
}
}
}
})}
message = Message(subject=subject, body=body, extra_headers=headers)
mail.send(message)
答案 1 :(得分:0)
您可以在设置中禁用点击跟踪:Disable clicktracting in sendgrid
顾名思义,此功能用于跟踪点击次数。默认情况下,sendgrid 还会在 HTML 电子邮件中添加一个不可见的图像,以跟踪它们是否已被打开。