Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add unsubscribe links to my emails when sending via sendgrid/mail

I'm sending emails using: https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail

I have not been able to find out HOW I can add the <a href="[Unsubscribe]">Unsubscribe</a> equivalent. This is documented in here: https://sendgrid.com/docs/Classroom/Basics/Marketing_Campaigns/unsubscribe_groups.html#-Using-a-Custom-Unsubscribe-Link

On the website, you just use a shortcode [Unsubscribe], this does not work when sending emails via the sendgrid/mail package.

like image 422
James111 Avatar asked Mar 19 '18 21:03

James111


People also ask

How do I add unsubscribe link to email in SendGrid?

Adding an Unsubscribe Group to your Email Using the Design Editor: Select your preferred Unsubscribe Group by clicking Settings and selecting the group from Recipients. From the Build tab, drag the Unsubscribe module to insert Sender Information and a link to the {{{unsubscribe}}} tag.

Does SendGrid handle unsubscribe?

If you are sending Transactional email through the SendGrid API or SMTP and have the Subscription Tracking setting turned on, an unsubscribe option will be added to the footer of every email that gets sent through your account.

How do you implement an unsubscribe link?

Insert with link toolType in the text you want to link, like "Unsubscribe from this list," and highlight it. Click the link icon in the toolbar. Type or paste the *|UNSUB|* merge tag into the Web Address (URL) field. Click Insert.


2 Answers

Since you're sending using code, it's a "transactional" type of message. You'll want to either turn on the Subscription Tracking filter at the account level (via [UI](subscription tracking setting) or API), or turn it on as you send the message, as part of the mail/send API call, under tracking_settings.

It's important to note that you can't mix those. If you define anything in the mail/send API call, you'll need to define everything for Subscription Tracking in that call. SendGrid won't look at some settings at the mail level, and some at the account level.

Most users will just set it at the account level. There, you can customize the HTML & Text of the Unsubscribe footer, customize the HTML of the landing page, or redirect landing to a URL of your choosing, which will send the recipient there with [email protected] in the URL string for your system to catch. You can also define the "replacement tag" like [%unsubscribe%], so that you can place the URL wherever you want within your HTML.

like image 187
jacobmovingfwd Avatar answered Oct 22 '22 21:10

jacobmovingfwd


One tip that would have saved me an hour or two is that:

It's possible to send the following in the api json along with other stuff:

  "asm":{
    "group_id":123,
    "groups_to_display": [123],
    }

then the following variables become available to use within the template:

<%asm_group_unsubscribe_raw_url%>
<%asm_preferences_raw_url%>

If you want to keep things simple don't include the following variable as it fiddles with too many things (this wasn't obvious from the documentation so obviously I did so and wasted time :( ):

  "tracking_settings": {
    "subscription_tracking": {
      "enable": true,
      "substitution_tag": "[unsubscribe_url]"
    }
  }

Just use them in their raw format and you shall be fine.

like image 41
Saint Avatar answered Oct 22 '22 22:10

Saint