Handling email in your test environment

We’ve had a few support requests asking if Postmark has a sandbox environment for testing. While we don’t have an actual test environment, we do have some methods and recommendations on how to properly test email in your development environment.

Why have a test environment? #

Let me explain why a test environment is important. When sending email from a staging or development environment, the first thing you want to avoid is sending email to real users by mistake. Over the years, this bit us a few times when trying to use some “real data” for testing. The other reason is so you can inspect the outbound messages and make sure they both display correctly, but have the proper headers and so on. Waiting until a production launch for this could be a disaster.

The solution #

There are two great solutions to properly test when it comes to outbound email.

Testing with the API

Postmark allows you to pass the API Key “POSTMARK_API_TEST” instead of your real API Key. This way, you can test that the request is valid and test against the various API responses from Postmark. This method will not allow you to inspect the messages, but it helps ensure that your messages will be accepted by the API.

Testing with SMTP

If you use the SMTP option for sending email, there is an excellent app (Mac OS X only) to handle this for you. It’s called MockSMTP. With MockSMTP, it will create a local SMTP server that you can point to in your local development environment. When emails are sent, you can view the actual display of the content as well as the RAW content of the message. This goes a long way when it comes to inspecting message content and ensuring the proper email events are triggered in your app, all without the risk of sending live emails.