Mandrill to SendGrid Migration: Our Experience

Previously we outlined a few alternatives to Mandrill given their parent company’s shift out of the transactional email space. This posed major problems for developers as well as our clients here at 86Pixels given the volume. Most of our clients integrated with Mandrill in a fairly basic fashion, just using it for password reminders and system updates, and for the most part, we were able to migrate them to SparkPost. SparkPost is great, they have Slack chats for support, good documentation, NodeJS support and a user interface that is strikingly similar to that of Mandrill.

However, for our other products like Subcast and CartHero, we were having issues using SparkPost as we had the need to send email from multiple domains on a single account. Google and similar email clients show this type of behavior in the From: field as “From via”. This is useful because we couldn’t afford to have all of our users insert the required DNS records to validate their domains, and SendGrid does this out of the box.

CartHero sends out abandoned cart emails to clients, and we want to send from the domains of our customers so that the emails appear with their branding attached in the “from” address as well as in the email body.

Step 1: Register on SendGrid

Registration on SendGrid was a snap, just fill out their signup form and check your email for an activation link. It takes a few minutes from them to provision your account, but you can set other things up in the mean time.

Step 2: Set up a Whitelabel Domain

Whitelabel domains in SendGrid are basically there to mask off the fact that you’re sending from SendGrid as much as possible. For doing open and click tracking (like CartHero does), it’ll use your whitelabel domain in the href field rather than a SendGrid domain, and the headers will match your domain. When you log into your dashboard for the first time, below the graph on the home page you’ll see the following:

Screen Shot 2016-03-21 at 7.37.07 PM

Click on “Set Up + Configure” under whitelabels to set this service up. For CartHero, we just chose a cute name like “” Once you click “OK” on the popup screen that asks for your domain, you will see the following screen prompting you to enter some new DKIM records (which is a fancy way of saying “we need you to verify your domain so other email providers will accept your emails.”)

Screen Shot 2016-03-21 at 7.40.45 PM

On this screen, you will have a few different records you need to enter into your DNS settings (most likely where you registered your domain name). They are all CNAMES, not TXT records like other providers. So we just set those records up, wait a few minutes and clicked “Validate Record” until everything went green. Once that was in effect, we’ve set up our domain with SendGrid!

Step 3: Add the trimmings (Open Tracking/Click Tracking)

One of the major things we needed was click/open tracking on the emails so that CartHero customers could determine the effectiveness of their email campaigns. This was relatively simple to do once you actually find where SendGrid has it tucked away. (Inside of Settings -> Tracking)

Screen Shot 2016-03-21 at 7.46.33 PM

For CartHero, we enabled Click and Open tracking. One great feature is “Subscription Tracking” which will automatically add the “Unsubscribe” link to the email footer as well as a physical address which ensures CAN-SPAM compliance! CartHero already does this out of the box, so we didn’t need to enable this feature in SendGrid.

Step 4: WebHooks

Now our application wouldn’t provide nearly as much value without actually being able to consume data about clicks, engagement and deliverability status messages in real time. Thankfully, SendGrid also has Webhooks support. This is tucked away under Settings -> Mail Settings -> Event Notification

Screen Shot 2016-03-21 at 7.51.20 PM

Here we’re able to set up our WebHook post URL as well as any actions that we will be notified of at that particular address. You can even hit “Test Your Integration” and you’ll get a sample capture of each type of selected action to see what the structure of the data will look like. Very useful for debugging and initial setup!

Step 5: Fire Away!

Now its time to send some email! CartHero is written in NodeJS, and thankfully SendGrid actually maintains a NodeJS package (SendGrid-NodeJS). Once we installed the NPM package, it was time to wire up our service to SendGrid. CartHero doesn’t use many canned templates. In fact, all email content is rendered by the server and sent as text/html. However, SendGrid does have pre-fabbed template support in their administration panel if you need that sort of thing!

We needed an API key to get CartHero to talk to SendGrid, so we went to Settings -> API Keys, clicked “Create new API Key” and selected “General API Key” and was greeted with the following screen:

Screen Shot 2016-03-21 at 7.58.41 PM

We made sure to grant Full Access for our API key to send mail (after all, thats the point!). We named the API key appropriately and saved the entry. BE SURE TO WRITE DOWN THE API KEY THAT THEY GIVE YOU. YOU WON’T BE ABLE TO SEE IT AGAIN.

Now, back in NodeJS land, we were able to do the following to fire off our first email:

var sendgrid = require('sendgrid')('YOUR_SENDGRID_API_KEY');
var email = new sendgrid.Email({
 to: '',
 from: '',
 subject: 'Test SendGrid',
 text: 'Hello world',
 html: '<strong>Hello world</strong>'
var res = sendgrid.send(email, function(err, json) {
 if (err) { return console.error(err); }

Thankfully, SendGrid automatically checks to see if our “From” header is from a different domain, and if it is, it automatically adjusts the Sender header and reply path so that the email is routed the best possible way. We can also specify both text and HTML outputs in one call.

The only drawback is that, in CartHero’s case, you need a unique message id for each email sent. This is so we can match our webhook events back up with the original message to know which email was opened or clicked. SendGrid does not give you a message id in the return call for send(). For that, you need to listen for the “delivered” webhook event and match the sender/recipient information up in the event data that is passed back to your application.

CartHero is glad to be a part of the SendGrid family, and we’re happy to have SparkPost there for our simpler transactional email needs (they have a much much much more liberal trial plan).

Subcast, being very similar to CartHero, will likely also use SendGrid as it is the best option available in terms of features, deliverability, price point and ease of integration.


If you have a project or product that needs its email Migrated off of Mandrill over to SendGrid, SparkPost, MailGun or anywhere else, don’t hesitate to contact us. Remember, zero-day is April 27, 2016 and 86Pixels is offering these services at a discounted hourly rate!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *