How to Monitor Your Mailgun Email API with Vigilmon
Mailgun is a developer-focused email API trusted by thousands of applications for transactional email delivery, email parsing, and email routing. When your Mailgun integration fails, password reset emails, account notifications, and automated reports go missing — often without any visible error to your users. This guide explains how to monitor your Mailgun API integration with Vigilmon.
Why Mailgun Monitoring Matters
Mailgun-related failures that affect production applications:
- Sending domain suspension for high bounce rates or spam complaints
- API authentication failures after key rotation or account changes
- Webhook delivery failures causing unprocessed inbound email events
- Rate limit hits during email broadcast campaigns
- EU vs US endpoint confusion causing requests to fail silently
Setting Up Mailgun Monitoring
1. Use Mailgun's Domain Validation Endpoint
Mailgun provides a domain status endpoint that's ideal for health checking without sending actual emails:
import requests
from flask import Flask, jsonify
app = Flask(__name__)
MAILGUN_API_KEY = "your-mailgun-api-key"
MAILGUN_DOMAIN = "mg.yourdomain.com"
@app.route("/health/mailgun")
def mailgun_health():
try:
# Check domain status - verifies API key and domain health
response = requests.get(
f"https://api.mailgun.net/v3/domains/{MAILGUN_DOMAIN}",
auth=("api", MAILGUN_API_KEY),
timeout=10
)
if response.status_code == 200:
domain_data = response.json()
state = domain_data.get("domain", {}).get("state", "unknown")
if state == "active":
return jsonify({"status": "ok", "domain_state": state})
return jsonify({"status": "degraded", "domain_state": state}), 503
return jsonify({"status": "error", "code": response.status_code}), 503
except Exception as e:
return jsonify({"status": "error", "message": str(e)}), 503
This endpoint:
- Verifies your API key is valid (401 if not)
- Confirms the sending domain is active (not suspended)
- Tests network connectivity to Mailgun's API
2. Add the Monitor in Vigilmon
- Go to vigilmon.online → Add Monitor
- Type: HTTP(S)
- URL:
https://yourapp.com/health/mailgun - Interval: 5 minutes
- Timeout: 15 seconds
- Expected status: 200
- Keyword check:
"status":"ok"
3. Monitor EU Region Separately (If Applicable)
If you use the EU API base (api.eu.mailgun.net), your domain check changes:
# EU region
response = requests.get(
f"https://api.eu.mailgun.net/v3/domains/{MAILGUN_DOMAIN}",
auth=("api", MAILGUN_API_KEY),
timeout=10
)
Add a separate Vigilmon monitor for EU vs US endpoints if you use both.
Webhook Endpoint Monitoring
Mailgun sends delivery events (delivered, bounced, failed, opened, clicked) to your webhook endpoints. If these are down, you lose delivery data and may not process unsubscribes correctly. Add a Vigilmon monitor for each webhook endpoint:
@app.route("/webhooks/mailgun", methods=["POST"])
def mailgun_webhook():
# Process Mailgun events
return jsonify({"status": "ok"}), 200
# Separate GET health check for Vigilmon
@app.route("/health/mailgun/webhook")
def webhook_health():
return jsonify({"status": "ok"})
Monitor /health/mailgun/webhook with Vigilmon to ensure your webhook processor is alive.
Domain Reputation Monitoring
Beyond API availability, monitor sending reputation:
| Metric | Healthy | Action Needed |
|---|---|---|
| Bounce rate | < 2% | Clean list at > 2% |
| Spam complaints | < 0.08% | Review content at > 0.1% |
| Domain state | active | Investigate if suspended |
| DKIM/SPF | Valid | Fix DNS if invalid |
Set up a weekly check of the Mailgun domain stats API to track these trends before they cause account suspension.
Alert Escalation
- API key 401: Immediate P0 — email sending is completely broken
- Domain suspended: P0 — check bounce/complaint rates, contact Mailgun support
- Webhook endpoint down: P1 — event data loss, may affect unsubscribes
- Rate limit 429: P2 — implement exponential backoff or batch queue
Conclusion
Email reliability is invisible until it breaks. Set up Mailgun monitoring with Vigilmon at vigilmon.online and get instant visibility into the health of your transactional email infrastructure.
Top comments (0)