Testing Email in Development post
When developing and application or a plugin locally, one setback that I have encountered is the inability to simply send emails from within a virtual machine. On a live site, the host normally offers a service for sending emails from you domain. There are two workarounds that I have found for testing email in a development environment:
- Setup a local SMTP Server (like MailCatcher)
- Utilize a Transactional Email Service (like Mailgun)
Local SMTP Server
Local SMTP Servers, like MailCatcher, allow you to test email in development just like a live site. Such services do not actually send the email to a live email address, but rather "catch" the emails and collect them in a local mailbox. This lets you simulate the email delivery process without hitting a live email address.
The downside to this approach is that you usually have to install the package manually, plus the additional steps of configuration. While there are plenty of resources to set this up in different environments, it is something to consider.
Transactional Email Service
Another approach is to utilize a Transactional Email Service. Such services, like Mailgun, provide an API for sending email. This makes sending email as simple as leveraging any other API, which as a developers is a very familiar experience.
If you use a transactional email service on your site, then there is an added benefit of using it locally, as then your development environment matches your live site.
There are many options to choose from when looking for a transactional email service, including Mailgun, as mentioned before, Postmark App, and SendGrid. For a curated list of options for comparison, check out the WP Ninjas article Transactional Email.
One potential downside of using an external service is that you now rely on the continuation of that service. (This is nothing new, as it is the same with any service or platform.)
In Recent News
In recent news, The Rocket Science Group, the company behind MailChimp, recently announced important changes to Mandrill, their transactional email service. What started as dogfooding an email delivery API, turned into a publicly available service leveraging the power and stability of the MailChimp platform. Many companies and developers began using this platform as the basis for their own applications and services, so the announcement of its discontinuation as a separate service is a shock to many.
Next time I'll cover strategies to decouple services from your application, so as to make these sudden changes less of a blow.