Using Mailgun with Meteor
Meteor makes it pretty simple to send E-Mails with the help of the E-Mail package.
In development mode you see the E-Mail content in your console when E-Mails are sent. This is a really good functionality because you don’t have to deal with the E-mail setup.
But as soon as you deploy your app to a production environment you need to consider the setup of a professional E-Mail delivery system.
There are several services out there which make it pretty easy to setup an E-Mail delivery system.
One of those is Mailgun. In this blog post we’ll take a closer look how you setup Mailgun for your Meteor application so that all you E-Mails will hit the inbox.
Create a Mailgun account
The first thing you need to do is to sign up at Mailgun. Just head over to the sign up page and create a free account.
Mailgun will deliver 10.000 E-Mails per month for you for free. That’s as much as 300 per day which is pretty awesome.
Setup the MAIL_URL environment variable
Meteor handles the E-Mail setup with the help of the MAIL_URL environment variable so we need to construct this connection string with the information Mailgun provides us.
Sign in to your Mailgun account and head over to the domains section. You’ll have one active domain which was preconfigured for you (You can and should add another one which matches your applications configuration).
Click on the domain name to get to the domain related information.
Now you can see all the information which might seem intimidating at first. But don’t worry!
Let’s take a closer look at the form of the MAIL_URL environment variable
smtp://USERNAME:PASSWORD@HOST:PORT<br />
and replace it with the information Mailgun provides us. It should look something like this:
smtp://sandbox1e222942ad074cdda8dqscxc932d219b:2fxc2fc3bb2a8e74727f799109v96d42@smtp.mailgun.org:587<br />
Restart the application
Now we need to stop our application and restart it with the MAIL_URL environment variable:
MAIL_URL=smtp://sandbox1e222942ad074cdda8dqscxc932d219b:2fxc2fc3bb2a8e74727f799109v96d42@smtp.mailgun.org:587 meteor<br />
That’s it. If you use a functionality which will send an E-Mail you’ll no longer see the E-Mail in the console as it will be delivered directly to the recipients inbox. Now you may want to use real E-Mail addresses if you want to test something.
Monitoring the E-Mail delivery
Mailgun gives you great control to look if and how your E-Mails are sent. Head over to Logs-Page of your domain to see if and how your E-Mails are sent.
Other services
Mailgun is not the only E-Mail delivery provider. There are several other’s out there like SendGrid, Postmark or Mandrill.