SendGrid Sandbox Mode Explained

Testing emails can sometimes lead to accidentally spamming your actual users. And the more emails you send to test accounts, 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:

  • You have to include the ‘enable’ parameter in each request with a boolean value of true or false. You cannot enclose this value in the quotes.
  • If you include an optional ‘template_id’ parameter in your request, API will assume that the template contains a subject line and a body, and thus will not validate them.

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 to actually 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 feature, 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.

Join our newsletterOnly the best content, delivered once a month. Unsubscribe anytime.

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:

  • Really easy to use if you’re already a user of SendGrid API. All you need to do is enable the right parameter. It also doesn’t generate any additional costs (on top of the regular SendGrid subscription)
  • Doesn’t cause any emails to be sent, so has no impact on deliverability and no possibility of error
  • Reliable email verification, letting you avoid many bounces

Due to its simplicity, there are also obvious limitations:

  • Can’t be used to preview emails, needs to be supported with another tool
  • Doesn’t validate HTML behind emails
  • Spam check no longer available
  • Can’t be used without a SendGrid plan

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’ inbox.

Arguably the best approach to email testing is with a pre-production testing environment. And the most popular tool in this sector is Mailtrap. Currently used by over 450 thousand of developers and QAs, it captures your test emails and lets you inspect them in the dedicated inbox. 

You can review the code behind them and quickly spot any errors. You can also assess the spam scores of your emails and set up auto-forwarding rules to share emails with your colleagues or clients. As a matter of fact, entire teams can collaborate on the email testing environment within the platform.

Add comment

E-mail is already registered on the site. Please use the Login form or enter another.

You entered an incorrect username or password

Sorry, you must be logged in to post a comment.