SendGrid Webhook Integration
SendGrid Event Webhooks provide real-time notifications about email events including deliveries, bounces, opens, clicks, and more. Monitor your email campaigns and transactional emails with detailed engagement tracking.Quick Start
- Get your Unhook URL:
https://unhook.sh/wh_YOUR_ID
- Configure in SendGrid: app.sendgrid.com/settings/mail_settings/webhook
- Start receiving events locally:
unhook listen
Configuration Steps
1. Access SendGrid Event Webhook Settings
Navigate to SendGrid Settings:- Direct Link: app.sendgrid.com/settings/mail_settings/webhook
- Or go to Settings → Mail Settings → Event Webhook
2. Configure Event Webhook
- Toggle Event Webhook Status to Enabled
- Enter your HTTP Post URL:
- Select Actions to be POSTed
3. Select Event Types
Choose the events you want to receive:Engagement Events
- Processed - Message accepted by SendGrid
- Dropped - Message dropped (bounced address, unsubscribed, etc.)
- Delivered - Message delivered to recipient server
- Deferred - Temporary delivery failure
- Bounce - Permanent delivery failure
- Open - Recipient opened email
- Click - Recipient clicked a link
- Unsubscribe - Recipient unsubscribed
- Spam Report - Marked as spam
- Group Unsubscribe - Unsubscribed from suppression group
- Group Resubscribe - Resubscribed to suppression group
4. Additional Configuration
Security Settings
-
Enable Signed Event Webhook:
- Toggle Signed Event Webhook Requests to ON
- Copy the Verification Key for signature validation
- This key is used to verify webhooks are from SendGrid
-
OAuth 2.0 (Optional):
- Enable if you need OAuth authentication
- Configure client credentials
Advanced Options
- Test Your Integration - Send a test POST
- Unique Arguments - Include custom data in events
- Categories - Filter events by category
5. Save Configuration
Click Save to activate your webhook endpoint.Event Payload Examples
Email Delivered
Email Opened
Link Clicked
Email Bounced
Webhook Security
Verify Event Webhook Signatures
SendGrid signs webhooks using ECDSA. Verify them:Best Practices
1. Handle Batch Events
SendGrid sends events in batches:2. Process Events Asynchronously
Don’t block the webhook response:3. Handle Duplicate Events
Use sg_event_id for deduplication:4. Store Raw Events
Keep raw event data for debugging:Testing Webhooks
Using SendGrid UI
- Go to Event Webhook settings
- Click Test Your Integration
- Select event types to test
- Click Send Test
Using cURL
Common Event Patterns
Track Email Journey
Monitor Bounce Rates
Environment Variables
Common Issues
Missing Events
- Ensure all desired event types are selected
- Check that webhook is enabled
- Verify URL is accessible
Signature Verification Failures
- Use the exact public key from SendGrid
- Ensure you’re using the raw request body
- Include proper newlines in the public key
Delayed Events
- Open and click events may be delayed
- Implement retry logic for critical operations
- Some events (like bounces) may take time to process
Large Payloads
- SendGrid batches up to 1,000 events
- Implement proper timeout handling
- Consider streaming large payloads
Useful Links
- SendGrid App: app.sendgrid.com
- Event Webhook Guide: docs.sendgrid.com/for-developers/tracking-events/event
- Event Types Reference: docs.sendgrid.com/for-developers/tracking-events/event#events
- Security & Validation: docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features
- API Reference: docs.sendgrid.com/api-reference
Support
Need help with SendGrid webhooks?- Join our Discord community
- Visit SendGrid Support
- Email us at support@unhook.sh