eithed
eithed

Reputation: 4339

Mailgun webhooks and live/staging server setup

We're running live/staging setup for our code - the code is deployed on staging, where it's tested and then it's deployed to live.

As such I'd like to make it, that Mailgun "knows" from which server the message originated from, and responds to that server, for that message with information about delivery status. From looking at the documentation I can't see a way to enable that - I can setup webhooks in the account, but I can't see how can I set them up with any logic, and, as such, Mailgun will notify live or staging, or both.

Is there a way to pass to Mailgun the URL where the webhooks should be fired, per message? I'd really like to manage it in the code, rather than logging into account and setting up rules/patterns there (somehow?)

Upvotes: 0

Views: 529

Answers (1)

gp42
gp42

Reputation: 545

I do not think sending a Webhook URL like you want it is possible with Maligun.

You can use one of the following approaches:

  1. Set up two domains, like
    • mx-staging.myapp.com - for staging
    • mx.myapp.com - for production

Then use a correct API url depending on your environment while sending the message. This will fire Webhooks only for the correct env, but requires additional logic in mail-sending and configuration of an extra domain. I believe this is the clean solution as it is logically separated.

  1. Set custom mail headers, like

X-Mailgun-Variables: {"environment": "staging"}

And then filter your actions based on this information. I do not consider this to be a good solution as it tangles two environments together and sends unnecessary traffic to both, but it serves your purpose of doing it completely in code. Here is the documentation on custom headers in malign.

Upvotes: 2

Related Questions