Articles / How to use Mailgun with CraftCMS
Feb 23. 2019 · by Helge Sverre

How to use Mailgun with CraftCMS

First off, some glossary, in the summary i mentioned that we use Mailgun for Transactional Emails, what that actually means is as follows:

Transactional emails are emails you send that contain information that the user needs, this can be things like password resets, new account detail emails, order summary or emails containing login information for a newly registered account.

An example of this is when you create a new user account in Craft CMS, they will Email that user an "Activate your account and set a password"-email to the email address set on the user account, this is a transactional email.

SendGrid defines Transactional Email it as the following:

Transactional email is a type of email sent to facilitate an agreed-upon transaction between the sender and the recipient. Transactional emails typically contain information a recipient wants or needs and consequently have very high open rates.

Read more about this here, I found it useful to know the difference between transactional email and other types of email (marketing emails), you might as well.

Back to Craft CMS

To use Mailgun as the email sending mechanism of our Craft CMS site, we need to add an email adapter, fortunately Pixel and Tonic has an official adapter for Mailgun that we can use!

First thing we need to do is sign up for a Mailgun account, I assume you know how to do this, so let's skip ahead to adding a new domain.

You need to add your domain to Mailgun's service and Verify your domain with them to be able to send email, this is so people can't signup with a random mailgun account and send vasts amount of spam emails seemingly coming from you.

Here are some good guides on setting up and verifying a mailgun domain.

Great

Now we've setup and verified our domain, now it is time to install and configure the Mailgun plugin:

Installing the Mailgun Adapter
BASH
# Tell composer to require the mailgun adapter in our project
composer require craftcms/mailgun

# Install the plugin
php craft install/plugin mailgun

Once Mailgun is installed, go to Settings → Email, and change the “Transport Type” setting to “Mailgun”. Enter your domain name and Mailgun API Key (which you can get from your domain overview page) and click Save.

Now mailgun is installed and activated, and all emails sent from your craft site will be going through Mailgun.

Helge Sverre Hessevik Liseth

Book 1:1 help from me on CodeMentor, get expert advice and help with CraftCMS, Flutter or Laravel.

Expertise
  • Flutter
  • CraftCMS
  • PHP
  • VueJS
Book session