Mailgun Service

Mailgun is a service which provides a way to send and receive email in response to events in your app. To use it, you need:

  • A MongoDB Stitch app with the Mailgun service enabled.
  • A Mailgun account with permission to send email.
  • At least one verified email address.

Set up Mailgun

If you already have a Mailgun account set up, you can skip this section.

  1. Visit Mailgun and create an account.
  2. Ensure that you have at least one authorized email address you can send to.
  3. Check your account’s Security tab for your API key and list of authorized recipients.
  4. Check your accounts list of domains.

Add a Mailgun Service to Your App

  1. If you don’t have a MongoDB Stitch app set up yet, see Getting Started.
  2. If your app doesn’t have a Mailgun service yet, click Add Service in the left side navigation.
  3. Select Mailgun.
  4. Enter a name for your service in the Service Name box.
  5. Click Add Service.
  6. Enter your Mailgun domain and API key.
  7. Click Save.
  8. Click the Rules tab.
  9. Click the ADD RULE button.
  10. Check the Send box in the ACTIONS column and enter any necessary rules in the WHEN box.
  11. Click the SAVE button in the lower right corner.

Send a Test Email with the Debug Console

  1. Navigate to the MongoDB Stitch console in your web browser.

  2. If your MongoDB Stitch app doesn’t have any users yet:

    • Click Authentication in the left nav of the console.
    • Click the Edit button in the API Keys row.
    • Create an API key.
  3. Click Debug Console in the left side navigation.

  4. Click choose user... near the top of the page. Select an app user.

  5. Mouse over the Pipeline to execute: section and click the edit icon.

  6. Select your app’s Mailgun service from the Service dropdown menu.

  7. Select send from the Action dropdown menu.

  8. Add the following document to the Arguments input box. Fill in the JSON values appropriately.

    "to": [
    "from": "",
    "subject": "Mailgun test",
    "text": "This is a Mailgun test message."

    Make sure the to address is on your Mailgun account’s list of authenticated recipients.

  9. Click Execute. The result should be an empty array.

      "result": []
  10. Check the recipient’s inbox.


    The message is sent by Mailgun. Depending on your email provider’s policies and your Mailgun setup, the message’s From address may not match the sender’s identity. Check your junk mail folder if you don’t see the message in your inbox.