Site icon Mailtrap

SendGrid Sandbox Mode Explained

Testing emails can sometimes lead to accidentally spamming your actual users. And the more test emails you send, the worse impact it will have on your deliverability. So what’s the best way to go about sending test emails? Not sending them at all. With SendGrid Sandbox, you can test your emails without any risks. How does it work? Is it worth your time? Let’s see.

How does SendGrid Sandbox work?

Sandbox mode is available for SendGrid subscribers and is a part of SendGrid API v3. If you’re a SendGrid client, you can enjoy it at no additional cost.

In Sandbox mode, you can send test emails and quickly validate if they’re sent and delivered but also if they’re formatted properly. The trick is that requests are executed but no emails are delivered to any inboxes. You protect yourself from any potential risk and get immediate feedback on the quality of your templates.

When a request is made, SendGrid validates its parameters as well as the structure of the JSON payload. It then returns a result of a check. When everything’s fine, you’ll see a 200 OK response. Otherwise, you’ll see an error explaining what went wrong.

Things to keep in mind:

Examples of SendGrid Sandbox mode JSON

Here’s an example of a valid Sandbox request:

{
	"personalizations": [{
		"to": [{
			"email": "mike@mailtrap.io"
		}],
		"subject": "Whassup dude"
	}],
	"from": {
		"email": "piotr@mailtrap.io"
	},
	"content": {
		"type": "text",
		"value": "Do you copy?"
	},
	"mail_settings": {
		"sandbox_mode": {
			"enable": true
		}
	}
}

As we mentioned above, it would result in a 200 OK response. Note that you won’t see here a typical 202 ACCEPTED response. It’s used only in the non-Sandbox environment.

Now let’s change some parameters to break the code. The simplest way to go about it would be by turning the email address into something that doesn’t resemble an email address anymore, like a link to a funny giphy. 

{
	"personalizations": [{
		"to": [{
			"email": "https://media.giphy.com/media/d8v55gXkiNj3y/giphy.gif"
		}],
		"subject": "Whassup dude"
	}],
	"from": {
		"email": "piotr@mailtrap.io"
	},
	"content": {
		"type": "text",
		"value": "Do you copy?"
	},
	"mail_settings": {
		"sandbox_mode": {
			"enable": true
		}
	}
}

Sending such a request will result in the following error:

{
  "errors": [
    {
      "field": "to",
      "message": "The to object must at least have an 'email'
parameter with a valid email address and may also contain a 'name' parameter. e.g. {"email": "example@example.com"} or {"email": "example@example.com", "name": "Example Recipient"}"
    }
  ]
}

The error notifications are quite descriptive and should help you get back on track very quickly.

Inspect & Debug Your Emails

How else can you test email sending with SendGrid?

SendGrid has two more features that may be of use.

If you just want to check the email sending speed, SendGrid offers a ‘black hole’ email for these purposes (no worries, these emails are not sent to Mailchimp’s black hole!). It’s especially useful when you have a large campaign to send out and want to estimate how long it may take. Ultimately, SendGrid limits the number of requests to 100,000 per second to prevent throttling.

To use this feature, you can route your messages to any email address on the @sink.sendgrid.net domain. Emails will be accepted and then immediately deleted, so you won’t get actually to see them in any inbox. Note that regular SendGrid credits are used just as though you were sending actual emails. Since the emails never leave the SendGrid servers, this tactic can’t be used for IP warmup on dedicated IPs.

With both the API and Marketing Campaigns features, you can also send yourself (or a colleague) a test email of your choice. This way, you can verify whether or not it displays as expected (you can also inspect its headers and body this way). Additionally, the tool runs a link validation test.

Pros and cons of using SendGrid Sandbox

Although the Sandbox mode is very simple, it’s a pretty valuable resource. Here are its main pros:

Due to its simplicity, there are also obvious limitations:

What to use if SendGrid Sandbox isn’t enough?

As you can see, Sandbox mode is good for basic purposes but falls short when you need more than that. You can amplify it by using other testing features from SendGrid. But to run complex, error-proof tests you probably need a dedicated tool for email testing.

There are various approaches to the problem. You could create a farm of fake emails for testing and send your test emails there. You could also mask the email addresses from your production database and perform the necessary tests with this data. But with either approach, you’re still hurting your deliverability and risking a random wave of test emails arriving in your users’ inboxes.

Arguably the best approach to email testing is with a testing environment. And the most comprehensive tool in this sector is the Mailtrap Sandbox for secure email testing. Currently used by over one million developers and QAs, it captures your emails at staging and lets you inspect them in the dedicated inbox. 

Use Mailtrap Email Sandbox to catch SMTP traffic, validate HTML/CSS, preview and debug emails in staging before sending them to users. . Test the strength of your templates by automating your test flows and scenarios with our flexible API. Analyze them with spam score check and share multiple inboxes for different projects and stages with your colleagues. As a matter of fact, entire teams can collaborate on the email testing environment within the Mailtrap Email Sandbox. Learn more about Mailtrap here.

Exit mobile version