You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Mailgun Webhooks与Live/Staging服务器配置的技术咨询

Answer

Great question—yes, Mailgun does support specifying custom webhook callback URLs on a per-message basis, which is exactly what you need for your Live/Staging deployment setup. This lets you keep all configuration in your code and ensure status updates go directly to the corresponding environment's endpoint without relying on account-level rules.

Here's how to implement it:

Per-Message Webhook Overrides via API

When sending an email through Mailgun's API, you can include specific parameters to override the default webhook URLs for that individual message. The two key parameters are:

  • o:delivery-webhook: Use this to set the URL where Mailgun will send delivery status events (deliveries, bounces, complaints, failures, etc.).
  • o:tracking-webhook: Use this if you want to override the default URL for open/click tracking events.

Example cURL Request

curl -s --user 'api:YOUR_MAILGUN_API_KEY' \
    https://api.mailgun.net/v3/your-domain.com/messages \
    -F from='Your App <noreply@your-domain.com>' \
    -F to='user@example.com' \
    -F subject='Test from Staging' \
    -F text='This is a test message from our staging environment.' \
    -F o:delivery-webhook='https://your-staging-app.com/webhooks/mailgun/delivery' \
    -F o:tracking-webhook='https://your-staging-app.com/webhooks/mailgun/tracking'

Important Details

  • Dynamic Configuration: In your code, just switch the webhook URL based on whether you're sending from Live or Staging. No dashboard changes required—all logic lives in your deployment pipeline or app config.
  • Endpoint Requirements: Make sure your webhook endpoint is publicly accessible (Mailgun needs to POST to it) and can parse Mailgun's standard webhook payload format.
  • Partial Overrides: You don't have to use both parameters—if you only care about delivery status, just include o:delivery-webhook and leave the tracking webhook as the account default (or vice versa).

This approach aligns perfectly with your preference to manage configuration in code, and ensures each environment only receives status updates for the messages it sent.

内容的提问来源于stack exchange,提问作者eithed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:39:56