3

How to tell sendgrid to stop decorating plain text URLs?

Using sendgrid SDK for Python, if that matters.

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)

For HTML-side this already has an answer:

Is it possible to exclude links from tracking

Tracking still needed for HTML parts of mails.

Roman Susi
  • 4,135
  • 2
  • 32
  • 47
  • 1
    Turn off click tracking in your SendGrid settings in the portal. – Barmar Jan 23 '18 at 09:30
  • 1
    that is still needed, but not on everything in plain text. THe setting most probably will affect html as well. updated question – Roman Susi Jan 24 '18 at 08:04
  • Yes, we use that setting to turn off click-tracking in our HTML emails. Our users have been suspicious when they hover over html links and the URL doesn't match the link we say they can paste manually. – Barmar Jan 24 '18 at 15:42
  • 1
    it's a different case, not this question. We need click-tracking in HTML mails, but not in plain text ones. – Roman Susi Jan 27 '18 at 15:45
  • Then I think you may be out of luck. I don't think there's a way to customize it on per-message basis, and only HTML has attributes to control it in the anchor. – Barmar Jan 28 '18 at 03:07
  • 1
    You could try asking SendGrid Tech Support, I generally find them helpful. – Barmar Jan 28 '18 at 03:08
  • Ok. I will report the results here if no-one answer first. – Roman Susi Jan 28 '18 at 07:57
  • any results? I have a similar problem – orirab Nov 10 '19 at 07:18
  • No results. Seems like support was not contacted, can't find it. – Roman Susi Nov 10 '19 at 08:28

2 Answers2

6

I contacted support and they informed me that I could use Clicktrack SMTP filter with the X-SMTPAPI header.

There are two filter options, one is the enable and disable the click-tracking setting and the other for enabling or disabling click-tracking links in the Plain-Text portion of the message.

The Sendgrid Python client has helper class ClickTracking to control these settings:

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)

A flask-mail example setting the `X-SMTPAPI' header with clicktrack filter:

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)

Cas
  • 6,123
  • 3
  • 36
  • 35
1

You can disable click tracking in settings: Disable clicktracting in sendgrid

This feature is there to track clicks as the name says. By default sendgrid also adds An invisible image is being appended to HTML emails to track if they have been opened.

nofoobar
  • 2,826
  • 20
  • 24