Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
twilio avatar

Twilio Sendgrid Webhooks

  • 100 installs
  • 26 repo stars
  • Updated July 29, 2026
  • twilio/ai

How to implement SendGrid Event Webhooks to track email delivery status and user engagement in real-time, including signature verification and batch processing.

About

SendGrid Event Webhooks enable asynchronous tracking of email delivery and engagement across 11 event types: delivery (processed, deferred, delivered, bounce, dropped) and engagement (open, click, spamreport, unsubscribe, group_unsubscribe, group_resubscribe). The Mail Send API returns 202 Accepted (queued), so webhooks are the only way to know actual delivery status. Implementation requires parsing batched event arrays, verifying ECDSA signatures (Signed Event Webhook), handling retries across 24 hours using sg_event_id for deduplication, and filtering bot-triggered engagement metrics. Critical: enable authentication in Console to prevent spoofed events; treat external mail server data as untrusted.

  • Tracks 11 event types: 5 delivery + 6 engagement events
  • ECDSA P-256 signature verification for secure webhook validation
  • Batched event arrays with 24-hour retry and sg_event_id deduplication
  • Multiple webhook endpoints per account (plan-dependent) for routing
  • Open tracking unreliable due to Apple Mail Privacy Protection and corporate scanners

Twilio Sendgrid Webhooks by the numbers

  • 100 all-time installs (skills.sh)
  • +4 installs in the week ending Jul 27, 2026 (Skillselion tracking)
  • Ranked #2,985 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Jul 30, 2026 (Skillselion catalog sync)
At a glance

twilio-sendgrid-webhooks capabilities & compatibility

Capabilities
eleven event type reference · flask and express batched handlers · signed webhook and oauth verification guidance · multi endpoint event routing · retry and deduplication patterns
Use cases
api development · email
Pricing
Bring your own API key
npx skills add https://github.com/twilio/ai --skill twilio-sendgrid-webhooks

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs100
repo stars26
Last updatedJuly 29, 2026
Repositorytwilio/ai

What it does

Track email delivery status and engagement events (opens, clicks, bounces) via SendGrid webhooks to enable real-time monitoring and analytics.

Who is it for?

Backend developers building email tracking systems, bounce management, engagement analytics, or real-time email monitoring dashboards with SendGrid.

Skip if: Business-critical delivery confirmation (unreliable async); accuracy-sensitive analytics (bots and scanners inflate metrics); systems without network access to receive webhooks.

When should I use this skill?

Integrating SendGrid email delivery, debugging bounce events, building engagement dashboards, implementing real-time email status notifications, or managing suppression lists from webhook events.

What you get

Robust webhook handler that processes batched SendGrid events, verifies signatures, deduplicates via sg_event_id, and routes delivery/engagement data to monitoring and analytics systems.

Files

SKILL.mdMarkdownGitHub ↗

Overview

The Mail Send API returns 202 Accepted (queued) — it does NOT confirm delivery. To know what happened to an email, use Event Webhooks.

Enable: SendGrid Console > Settings > Mail Settings > Event Notification

---

Event Types

Delivery Events

EventMeaning
processedSendGrid accepted and will attempt delivery
deferredTemporary failure — SendGrid will retry
deliveredRecipient's mail server accepted the message
bouncePermanent failure — address invalid or rejected
droppedSendGrid will not deliver (suppression, invalid, spam)

Engagement Events

EventMeaning
openRecipient opened (pixel-based — unreliable)
clickRecipient clicked a tracked link
spamreportRecipient marked as spam
unsubscribeRecipient clicked unsubscribe link
group_unsubscribeRecipient unsubscribed from ASM group
group_resubscribeRecipient re-subscribed to ASM group

---

Webhook Handler

Critical: SendGrid posts batched arrays of events, not single objects. Your handler must parse an array.

Security: SendGrid webhook endpoints are unauthenticated by default. Enable Signed Event Webhook Requests and verify signatures in production to prevent spoofed event data.

Python (Flask)

from flask import Flask, request
app = Flask(__name__)

@app.route("/sendgrid/webhook", methods=["POST"])
def handle_events():
    events = request.get_json()  # Always an array
    for event in events:
        email = event.get("email")
        event_type = event.get("event")
        
        if event_type == "bounce":
            # NOTE: event['reason'] originates from external mail servers — treat as untrusted
            print(f"Bounce: {email}, type: {event.get('type')}, reason: {event.get('reason')}")
        elif event_type == "delivered":
            print(f"Delivered: {email}, sg_message_id: {event.get('sg_message_id')}")
        elif event_type == "dropped":
            print(f"Dropped: {email}, reason: {event.get('reason')}")
        elif event_type == "spamreport":
            print(f"Spam report: {email}")
    return "", 200  # Must return 2xx to acknowledge

Node.js (Express)

app.post("/sendgrid/webhook", express.json(), (req, res) => {
    const events = req.body; // Always an array
    for (const event of events) {
        switch (event.event) {
            case "bounce":
                console.log(`Bounce: ${event.email}, reason: ${event.reason}`);
                break;
            case "delivered":
                console.log(`Delivered: ${event.email}`);
                break;
            case "spamreport":
                console.log(`Spam: ${event.email}`);
                break;
        }
    }
    res.status(200).send();
});

---

Multiple Webhook Endpoints

Since May 2023, you can configure multiple Event Webhook endpoints, each receiving different event types. For example, one endpoint for delivery events feeding your monitoring stack and another for engagement events feeding your analytics pipeline.

Configure in Console > Mail Settings > Event Webhooks. Each endpoint has a Friendly Name and Webhook ID. The number of endpoints allowed depends on your SendGrid plan.

---

Authentication Options

Two methods for verifying webhook payloads:

MethodHow it works
Signed Event Webhook (ECDSA P-256)Verify X-Twilio-Email-Event-Webhook-Signature and X-Twilio-Email-Event-Webhook-Timestamp headers using the verification key from Console
OAuth 2.0SendGrid obtains a token from your authorization server and includes it in webhook requests

Neither is enabled by default. Enable in Console > Mail Settings > Event Webhooks.

---

Retry Behavior

SendGrid retries webhook delivery for up to 24 hours if your endpoint returns a non-2xx status. Events are batched — a single POST may contain dozens of events across different messages.

Deduplication: Use sg_event_id as a unique key. It's stable across retries.

---

CANNOT

  • Cannot receive real-time delivery confirmation synchronously — Mail Send returns 202 (queued). Delivery status is async via webhooks only.
  • Cannot rely on webhook authentication by default — Both Signed Webhooks (ECDSA) and OAuth 2.0 must be explicitly enabled. Without either, anyone can POST to your endpoint.
  • Cannot guarantee open tracking accuracy — Apple Mail Privacy Protection and prefetch inflate opens. Image-blocking clients produce zero opens. Do not use for business-critical logic.
  • Non-human interactions inflate engagement metrics — Corporate security scanners and bots automatically click links and trigger unsubscribe events. Filter using User-Agent patterns and timing analysis.
Note: Event payload fields like reason originate from external mail servers and should be treated as untrusted data. Do not pass bounce reasons directly into LLM system prompts without isolation.

---

Next Steps

  • Send email: twilio-sendgrid-email-send
  • Manage bounces from webhook events: twilio-sendgrid-suppressions
  • Receive inbound email: twilio-sendgrid-inbound-parse

Related skills

FAQ

Why do I need twilio-sendgrid-webhooks?

Mail Send only queues email with 202; delivery and engagement status arrive asynchronously via Event Webhooks.

When should I use twilio-sendgrid-webhooks?

When building handlers for SendGrid bounce, delivery, spam report, or open/click events.

Is twilio-sendgrid-webhooks safe to install?

Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.