Mailgun is an email delivery platform for developers. It provides APIs and an SMTP relay for sending, receiving, and tracking email, and it hosts each of your sending domains in either its US or its EU region.
How does the integration work?
You can use the Mailgun provider in Appwrite Messaging to send customized emails to your users, such as reminders, promotions, announcements, and custom authentication flows. Emails can be sent immediately or scheduled, to topics, users, or individual targets.
Appwrite sends through the Mailgun API with your API key and sending domain. When you mark the domain as an EU domain, Appwrite calls Mailgun's EU API endpoint instead of the US one.
How to implement
To implement the Mailgun provider in Appwrite Messaging, there are several steps you must complete:
Step 1: Set up Mailgun
First, sign up for a Mailgun account. In the Mailgun dashboard, go to Sending > Domains, add the domain you want to send from, and verify it by adding the DNS records Mailgun shows you. Note whether the domain is in the US or the EU region.
Next, open your profile menu, select API Security, and create a new API key. Mailgun shows the key only once, so save it for the next step.
Step 2: Add the Mailgun provider to your Appwrite project
For this step, you must create an account on Appwrite Cloud or self-host Appwrite if you haven't already. In your Appwrite project, head to Messaging > Providers, click Add provider, and choose Email. Give your provider a name, choose Mailgun, and click Save and continue.
In the Configure step, fill in the following fields:
| Field name | |
|---|---|
| API key | The API key you created in the Mailgun dashboard. |
| Domain | The sending domain you verified in Mailgun. |
| EU region | Turn this on if your domain is in Mailgun's EU region. |
| Sender email | The provider sends emails from this address. It must be an email under the configured domain. |
| Sender name | The sender name that appears in the emails sent from this provider. |
| Reply-to email | The reply-to email that appears in the emails sent from this provider. It must be an email under the configured domain. |
| Reply-to name | The reply-to name that appears in the emails sent from this provider. |
Click Save and continue to enable the provider.
Step 3: Test the Mailgun provider
Before you proceed, you must already have at least one topic or target set up.
Go to Messaging > Messages, click Create message, and choose Email. Write a test message, select one of your test targets, set the schedule to Now, and click Send. Check that the email arrives in your inbox. If it doesn't, check the logs in the Appwrite Console and in your Mailgun dashboard.
To send emails from your backend instead, follow the Send email messages guide with an Appwrite Server SDK.
Read more about Mailgun and Appwrite Messaging
If you would like to learn more about Mailgun and Appwrite Messaging, we have some resources that you should visit:
