What is Mailgun?

Mailgun is basically quite powerful e-mailing service for app developers, who can use it for sending and processing e-mail from and to their applications. If you don’t understand this sentence, don’t worry, that’s not what we’ll be dealing with.

This is probably not relevant to most of you, but keep in mind, that if you want the Mailgun to be free, you can send and receive only 10 000 e-mails monthly.

1.  Mailgun account

First step is the easiest, you just need to create an account on Mailgun.com.

2. Add new domain

On the application dashboard, go to the Domains section and add a new domain. If you want to receive e-mails on your main address on this domain, you can easily ignore the Mailgun message and insert the domain name, e.g. yourdomain.com

3. Change the DNS records of your domain

Now comes the tricky part, because you need to edit the DNS records of your domain and every domain provider is different, so you just have to find this settings in the administration of your domain. Mailgun also offers you few hints for the most common ones.

Mailgun is showing you a page with a few instructions:

  • Add DNS Records for sending – Necessary DNS records which you need to set for sending e-mails.
  • Add DNS Records for tracking – You can skip this part if you won’t use API services and tracking.
  • Add DNS Records for receiving – Important part for receiving e-mails (and getting them to your GMail).

4. Wait for the propagation of DNS records

It takes a while to propagate the settings of DNS to the whole world (Mailgun says up to 48 hours), so you have to wait until your domain is marked as Active instead of Unverified.

5. Set sending from GMail

Setting a new sending address in GMail is easy nnd it works the same as for the other servers.

In your GMail account, click on the settings wheel, choose Settings and then Accounts and Import.

In section Send mail as click on Add another e-mail address, fill it in and in SMTP settings write “smtp.mailgun.org” on port 465. In username write postmaster@yourdomain.com. You can find these information also at Domain’s overview at Mailgun. On this place you will find the password as well, which you have to put to the last input.

That’s it, now you can send e-mail from this address. All you need to do is set the receiving.

6. Set receiving of e-mails to GMail

Go back to Mailgun and choose Routes. You can use them for routing e-mails and that’s what we’re gonna do. Routing received e-mails to your GMail address.

Click on Add Route and choose Match Recipient in Expression Type. Fil your e-mail address under yourdomain.com to the input Recipient, e.g. myemail@yourdomain.com.

Go down to Actions and check Forward and write your GMail address, to which you would like the e-mail to be routed. Click on Create Route.

And you’re done, now the e-mail which will arrive to myemail@yourdomain.com should be forwarded to your GMail account. And you will even see the original receiving e-mail in the head of the message!

Testing

I strongly recommend to test the whole setting, however I suggest do not send the test e-mail directly from GMail, because it won’t work as you expect. GMail sees that you are trying to deliver the email to yourself and instantly delivers the message.

If you have any trouble receiving the e-mails, check the Mailgun and section Logs, where you can see all operations performed on e-mails and you can easily find out, if the Mailgun is throwing your e-mails away.