Email best practices

What is a webhook? Real-time email event tracking with Mailjet

Find out what exactly and why you need it. Tracking events is easy using webhooks, this is why Mailjet offers you the possibility to use them with us.
Image for What is a webhook? Real-time email event tracking with Mailjet
August 29, 2025

Webhooks are a powerful way to receive real-time notifications when events occur in your email campaigns. This comprehensive guide will teach you what webhooks are, how they work with email systems, and how to implement Mailjet’s webhook functionality to track email events like opens, clicks, bounces, and more in real time.

By the end of this guide, you’ll understand how to set up and optimize webhook endpoints, handle different event types, and implement best practices for reliable, scalable email event processing.

What is a Webhook?

A webhook is a simple way for one system to notify another that “something just happened.” It’s an HTTP POST request sent to a URL you provide (your “webhook endpoint”) containing a JSON payload that describes the event. Unlike APIs that you poll on a schedule, webhooks are event-driven as they push data only when there’s something new to report.

Think of webhooks as the internet’s version of a phone call: instead of repeatedly checking if something happened, the system calls you immediately when it does.

Why teams use webhooks

Webhooks offer several advantages for email marketing and transactional email workflows:

  • Real-time notifications: Update your application the moment an email is opened or a link is clicked
  • Faster support and operations: Trigger alerts when bounce or block rates spike
  • Cleaner data management: Auto-sync unsubscribes and hard bounces to your CRM
  • Enhanced personalization: Send follow-up messages when customers engage (or don’t)
  • Better analytics: Stream events into your dashboards or data warehouse

Webhook vs API polling

Understanding the difference between webhooks and traditional email API polling helps illustrate why webhooks are often the better choice:

API pollingWebhooks
Pull data on a timer, even if nothing changedEvent-based push notifications
More requests and bandwidth usageFewer requests, more efficient
Delayed insights due to polling intervalsInstant updates when events occur
Complex scheduling and state managementSimpler automation workflows

How Mailjet email webhooks work

Mailjet can send webhook notifications for the following email events:

  • sent: Email was successfully sent
  • open: Recipient opened the email
  • click: Recipient clicked a link in the email
  • bounce: Email bounced (soft or hard)
  • blocked: Email was blocked by the recipient’s server
  • spam: Email was marked as spam
  • unsub: Recipient unsubscribed

Understanding webhook payloads

Each webhook contains a JSON payload with event-specific information. Here are examples of common event types:

Open event payload

                            

                                {
  "event": "open",
  "time": 1433103519,
  "MessageID": 19421777396190490,
  "email": "api@mailjet.com",
  "mj_campaign_id": 7173,
  "mj_contact_id": 320,
  "customcampaign": "",
  "CustomID": "helloworld",
  "Payload": "",
  "ip": "127.0.0.1",
  "geo": "US",
  "agent": "Mozilla/5.0 ..."
}
                            
                        

Bounce event payload

                            

                                {
  "event": "bounce",
  "time": 1430812195,
  "MessageID": 13792286917004336,
  "email": "bounce@mailjet.com",
  "blocked": true,
  "hard_bounce": true,
  "error_related_to": "recipient",
  "error": "user unknown"
}

                            
                        

Processing different event types

Each event type requires different handling strategies:

  • Unsubscribed/spam: Immediately suppress the contact across all systems
  • Hard bounce: Remove from mailing lists and stop future sends
  • Blocked: Inspect error details and provider information to diagnose deliverability issues
  • Click/open: Trigger follow-up campaigns, score engagement, and personalize customer journeys

Mailjet webhook best practices

Following these best practices ensures reliable webhook processing and optimal performance:

Response handling

  • Return HTTP 200 OK immediately: Acknowledge receipt as quickly as possible
  • Process asynchronously: Persist the payload to a queue or database, then process it separately

Reliability and security

  • Use HTTPS: Host your endpoint on a secure connection
  • Implement authentication: Protect your endpoint with basic auth or API keys
  • Monitor failures: Track non-200 responses to prevent URL suspension

Performance optimization

  • Minimize processing time: Do minimal work in the request handler to avoid timeouts
  • Use event grouping: Configure Version=2 to batch multiple events in single requests
  • Set up backup URLs: Configure failover endpoints to maintain event flow during outages

Retry behavior

Mailjet automatically retries failed webhook deliveries for up to 24 hours if your endpoint doesn’t return a 200 OK response. If repeated errors persist, the webhook URL may be suspended. You can configure a backup URL to ensure continuous event delivery.

Setting up Mailjet webhooks

You can configure Mailjet webhooks using either the API or the web interface. Here are both approaches:

This method offers more control and is ideal for automated deployments.

Step 1: Choose your event types

Decide which events you want to track: sent, open, click, bounce, blocked, spam, or unsub.

Step 2: Create the Webhook via API

Use the eventcallbackurl resource to configure your webhook:

                            

                                curl -X POST \
  https://api.mailjet.com/v3/REST/eventcallbackurl \
  -H 'Authorization: Basic <base64_encoded_api_key:secret>' \
  -H 'Content-Type: application/json' \
  -d '{
    "EventType": "open",
    "Url": "https://example.com/webhooks/mailjet/open",
    "Version": 2
  }'

                            
                        

Configuration notes:

  • Version=2 enables grouped events in a single POST request
  • Set “isBackup”: true on a secondary URL to create a failover endpoint

Step 3: Test your integration

Send a test email and perform the tracked action (open, click, etc.) to verify you receive webhook events.

Option B: Web interface setup (no-code option)

For teams preferring a visual interface:

  1. Log in to app.mailjet.com and navigate to Account Settings
  2. Under REST API, select “Event notifications (webhooks)”
  3. Add one URL for all events or define dedicated URLs per event type
  4. Test with real events rather than the “Send test” feature, which posts empty payloads

Webhook implementation examples

Here are minimal webhook receiver implementations in popular programming languages:

Node.js with express

                            

                                const express = require('express');
const app = express();

app.use(express.json());

app.post('/webhooks/mailjet/open', (req, res) => {
  // 1. Persist the event data quickly
  console.log('Received webhook:', req.body);
  // TODO: Save to queue or database
  // await saveToQueue(req.body);

  // 2. Acknowledge immediately
  res.status(200).send('ok');
});

app.listen(3000, () => {
  console.log('Webhook server running on port 3000');
});

                            
                        

Python with flask

                            

                                from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/webhooks/mailjet/open', methods=['POST'])
def handle_open_event():
    data = request.get_json()

    # Process the webhook data
    print(f"Received webhook: {data}")
    # TODO: Save to queue or database
    # save_to_queue(data)

    return jsonify({"status": "ok"}), 200

if __name__ == '__main__':
    app.run(port=3000)
                            
                        

Advanced configuration tips

Here are some tips to help you get even more from webhooks.

Batch processing at scale

Use Version=2 in your webhook configuration to reduce HTTP overhead by receiving multiple events in batched requests:

                            

                                {
  "EventType": "open",
  "Url": "https://example.com/webhooks/mailjet/batch",
  "Version": 2
}
                            
                        

Event correlation and tracking

Use CustomID and EventPayload parameters in your Send API calls to make webhook events easier to correlate with your internal systems:

                            

                                {
  "Messages": [{
    "To": [{"Email": "user@example.com"}],
    "Subject": "Welcome!",
    "TextPart": "Welcome to our service!",
    "CustomID": "user-123-welcome",
    "EventPayload": "campaign=onboarding&segment=new_users"
  }]
}

                            
                        

Enterprise-scale event streaming

For high-volume applications, consider streaming events to third-party queue services:

  • Azure Service Bus
  • Amazon SQS
  • Google Cloud Pub/Sub

Frequently asked questions

What events does Mailjet send to webhooks?

Mailjet sends sent, open, click, bounce, blocked, spam, and unsub events. Each contains the MessageID, contact and campaign identifiers, and event-specific details (such as url for click events).

How fast are events delivered?

Events are pushed shortly after they occur, typically within seconds. If your endpoint doesn’t respond with HTTP 200 OK, Mailjet retries delivery for up to 24 hours.

Can I reduce the number of webhook calls?

Yes. Configure grouped delivery by setting Version=2 on your eventcallbackurl so Mailjet batches multiple events in one POST request.

How do I secure my webhook endpoint?

Use HTTPS, protect the endpoint with basic authentication, and restrict access through IP filtering or API gateways. Always process payloads server-side and never expose webhook endpoints to client applications.

Quick setup checklist

Follow this checklist to implement Mailjet webhooks successfully:

  • [ ] Create and secure a public HTTPS endpoint
  • [ ] Configure eventcallbackurl via API or web interface
  • [ ] Implement quick HTTP 200 OK responses with asynchronous processing
  • [ ] Add CustomID and EventPayload to your email sends for easier correlation
  • [ ] Monitor webhook failures and configure backup URLs
  • [ ] Set up event streaming to your analytics or alerting systems

Next steps and additional resources

Now that you understand webhook fundamentals and implementation, consider exploring these related Mailjet features:

Summary

Webhooks provide a powerful, efficient way to receive real-time notifications about email events. By implementing Mailjet webhooks with proper error handling, security measures, and asynchronous processing, you can build responsive, data-driven email workflows that enhance customer experience and improve operational efficiency.

Remember to start simple, monitor your implementation closely, and scale your webhook processing as your email volume grows. With the foundation provided in this guide, you’re ready to harness the full power of real-time email event tracking.