Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendGrid development environment

What is the best approach for SendGrid development QA environments? We'd like non Production environments that we can store and test our email templates via the API. The SendGrid sandbox setting doesn't allow emails to actually be sent.

Unless there is a better approach, we plan on creating new SendGrid basic accounts for $9.95 a month which allows up-to 40K emails. with this approach, our Dev and QA environments will have different accounts that we can test and deploy with.

like image 942
Richard Butterwood Avatar asked Jan 02 '18 16:01

Richard Butterwood


2 Answers

I know this is an old question, but I would like to leave our solution here just in case someone else need it.

Sendgrid doesn't allow to have more than one environment, but you can test different content using their dynamic templates.

On your template you can set some conditionals if/elselike this:

{{#if isDev}}
  <p>This is development</p>
{{else}}
  <p>This is prod</p>
{{/if}}

And then, when you call the API for sending an mail you should pass the var like this (note: this is a Node example):

sendgrid.send({
  from: EMAIL_FROM,
  templateId: TEMPLATE_ID,
  personalizations: [{
    dynamic_template_data: {
      isDev:(process.env.ENV === 'development'),
    },
  }],
});

Obviously this is not the same has having different environment, as you we are not testing the final email you will be sending on PRO, cause your metrics will be mixed and, if you test too much, it can impact your sending quota. But it will work if you just test minor changes to time to time like we do.

like image 188
Coluccini Avatar answered Oct 17 '22 23:10

Coluccini


SendGrid does not have a UAT (User Acceptance Testing) type environment, so seperate users is their suggested solution.

My company took the approach to have different SendGrid users per environment. It allows API access and a separation of accounts, so a production account is not used in other environments. It could be tested using a free account for local or development work, and paid accounts for Staging, QA, or Beta type environments. SendGrid pricing has API access at all levels. Sometimes the trickiest thing with SendGrid testing is your limit on Subusers, which is limited at the lower pricing tiers.

like image 2
Christine Avatar answered Oct 18 '22 01:10

Christine