I have configured MailGun routing for two different targets. The first route sends emails to a specific email address and works properly. The second route is set up to send data to a REST API endpoint, and it also works as intended. However, my API requires certain custom headers for authentication and processing. Is there a way to set up MailGun routes to send these custom headers along with requests to my REST endpoint? I’m having trouble locating this option in the routing settings, and I need to pass authorization tokens in the headers.
Nope, MailGun’s routing system can’t add custom headers to REST endpoint requests. I hit this same wall about a year ago when I needed Bearer token auth for our internal API. My workaround was building a middleware layer - just a simple proxy that catches the MailGun webhook, adds the auth headers, then forwards everything to my actual API. You get full control over headers this way, plus you can handle token refresh if needed. You could also restructure your API to take auth params in the request body instead of headers, but that might not work depending on your setup.
MailGun’s routing doesn’t allow for custom headers to be included with requests to REST endpoints. I encountered a similar issue when needing to send authentication tokens. One solution is to utilize query parameters for authorization, if your API supports that method. Alternatively, you could configure your endpoint to extract authentication information from the POST body that MailGun forwards. In my case, I created a middleware that intercepts MailGun requests and appends the necessary headers before forwarding them to my API.
Yep, you got it! Mailgun routing doesn’t support adding custom headers straight up. What you can do is to manage auth on your endpoint by checking Mailgun’s signature. It’s a good practice for security. That’s the approach many users take!