Skip to main content

Mailgun

Profile Requirements

To deliver a message to a recipient over Mailgun, Courier must be provided the recipient's email address. This value should be included in the recipient profile as email.

JSON
{
"message": {
// Recipient Profile
"to": {
"email": "example@example.com"
}

// ... rest of message definition
}
}

Override

You can use a provider override to replace what we send to Mailgun's Messages API. For example, you can use Mailgun's Tagging with your request:

JSON
{
"message": {
"template": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"to": {
"email": "example@example.com"
},
"providers": {
"mailgun": {
"override": {
"body": {
"o:tag": "notifications"
},
"config": {
"apiKey": "<your API Key>",
"domain": "<domain>",
"host": "<host>"
}
}
}
}
}
}

Everything inside of message.providers.mailgun.override will replace what we send to Mailgun's Messages API. You can see all the available options by visiting Mailgun API docs.

EU Host

When sending from Mailgun's EU infrastructure, be sure to substitute the beginning of the endpoint https://api.mailgun.net with https://api.eu.mailgun.net, and include it in the config object of the override along with the apiKey and domain.

Sending Attachments

To include an attachment in the email, you can use the following override:

{
"message": {
"template": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"to": {
"email": "example@example.com"
},
"data": {
"hello": "world"
},
"providers": {
"mailgun": {
"override": {
"attachments": [
{
"filename": "billing.pdf",
"contentType": "application/pdf",
"data": "Q29uZ3JhdHVsYXRpb25zLCB5b3UgY2FuIGJhc2U2NCBkZWNvZGUh"
}
]
}
}
}
}
}

IP Address Range

Mailgun offers an additional security feature that can whitelist certain IP addresses from accessing their API. Courier is hosted on AWS and does not provide an IP range in the form of an allow list.

AWS provides a workaround by allowing users to subscribe and update the changes themselves. Whenever there is a change to the AWS IP address ranges, AWS will send notifications to subscribers of the AmazonIpSpaceChanged topic.