Can I stop a SendGrid mail if it received a certain parameter?

189 Views Asked by At

I'm using a certain SendGrid template for several different projects and am trying to find a way to stop emails from going out in some conditions, through SendGrid.

For example, lets say I'm passing SendGrid some parameters like: {id, name, amount, date}

I want to stop that email from going out when i'm passing a certain id.

I know that I can change the email template i'm sending with conditionals using handlebars: From here

But Can I actually stop the mail if some condition happens?

In my case, every time I send the id = 5

1

There are 1 best solutions below

0
On

You can control the body of the email using Handlebar templating, but by that point, you have already told SendGrid to send email with the data you provided. You cannot stop the email from being sent from within Handlebars.

If you're using code to tell SendGrid to send these emails, you could check in your code if the id equals 5, and if so, do not send an email.

If you're using Single Sends to send an email to SendGrid Contacts, you could to store this id field as a custom field, and create a segment or update your existing segment to filter out the contact with that id.