Postmark Webhooks
When to Use This Skill
- Setting up Postmark webhook handlers for email event tracking
- Processing email delivery events (bounce, delivered, open, click)
- Handling spam complaints and subscription changes
- Implementing email engagement analytics
- Troubleshooting webhook authentication issues
Essential Code
Authentication
Postmark does NOT use signature verification. Instead, webhooks are authenticated by including credentials in the webhook URL itself.
// Express - Basic Auth in URL
// Configure webhook URL in Postmark as:
// https://username:password@yourdomain.com/webhooks/postmark
app.post('/webhooks/postmark', express.json(), (req, res) => {
// Basic auth is handled by your web server or proxy
// Additional validation can check expected payload structure
const event = req.body;
// Validate expected fields exist
if (!event.RecordType || !event.MessageID) {
return res.status(400).send('Invalid payload structure');
}
// Process event
console.log(`Received ${event.RecordType} event for ${event.Email}`);
res.sendStatus(200);
});
// Alternative: Token in URL
// Configure webhook URL as:
// https://yourdomain.com/webhooks/postmark?token=your-secret-token
app.post('/webhooks/postmark', express.json(), (req, res) => {
const token = req.query.token;
if (token !== process.env.POSTMARK_WEBHOOK_TOKEN) {
return res.status(401).send('Unauthorized');
}
const event = req.body;
console.log(`Received ${event.RecordType} event`);
res.sendStatus(200);
});
Handling Multiple Events
// Postmark sends one event per request (not batched)
app.post('/webhooks/postmark', express.json(), (req, res) => {
const event = req.body;
switch (event.RecordType) {
case 'Bounce':
console.log(`Bounce: ${event.Email} - ${event.Type} - ${event.Description}`);
// Update contact as undeliverable
break;
case 'SpamComplaint':
console.log(`Spam complaint: ${event.Email}`);
// Remove from mailing list
break;
case 'Open':
console.log(`Email opened: ${event.Email} at ${event.ReceivedAt}`);
// Track engagement
break;
case 'Click':
console.log(`Link clicked: ${event.Email} - ${event.OriginalLink}`);
// Track click-through rate
break;
case 'Delivery':
console.log(`Delivered: ${event.Email} at ${event.DeliveredAt}`);
// Confirm delivery
break;
case 'SubscriptionChange':
console.log(`Subscription change: ${event.Email} - ${event.ChangedAt}`);
// Update subscription preferences
break;
case 'Inbound':
console.log(`Inbound email from: ${event.Email} - Subject: ${event.Subject}`);
// Process incoming email
break;
case 'SMTP API Error':
console.log(`SMTP API error: ${event.Email} - ${event.Error}`);
// Handle API error, maybe retry
break;
default:
console.log(`Unknown event type: ${event.RecordType}`);
}
res.sendStatus(200);
});
Common Event Types
| Event |
RecordType |
Description |
Key Fields |
| Bounce |
Bounce |
Hard/soft bounce or blocked email |
Email, Type, TypeCode, Description |
| Spam Complaint |
SpamComplaint |
Recipient marked as spam |
Email, BouncedAt |
| Open |
Open |
Email opened (requires open tracking) |
Email, ReceivedAt, Platform, UserAgent |
| Click |
Click |
Link clicked (requires click tracking) |
Email, ClickedAt, OriginalLink |
| Delivery |
Delivery |
Successfully delivered |
Email, DeliveredAt, Details |
| Subscription Change |
SubscriptionChange |
Unsubscribe/resubscribe |
Email, ChangedAt, SuppressionReason |
| Inbound |
Inbound |
Incoming email received |
Email, FromFull, Subject, TextBody, HtmlBody |
| SMTP API Error |
SMTP API Error |
SMTP API call failed |
Email, Error, ErrorCode, MessageID |
Environment Variables
# For token-based authentication
POSTMARK_WEBHOOK_TOKEN="your-secret-token-here"
# For basic auth (if not using URL-embedded credentials)
WEBHOOK_USERNAME="your-username"
WEBHOOK_PASSWORD="your-password"
Security Best Practices
- Always use HTTPS - Never configure webhooks with HTTP URLs
- Use strong credentials - Generate long, random tokens or passwords
- Validate payload structure - Check for expected fields before processing
- Implement IP allowlisting - Postmark publishes their IP ranges
- Consider using a webhook gateway - Like Hookdeck for additional security layers
Local Development
For local webhook testing, use Hookdeck CLI:
npx hookdeck-cli listen 3000 postmark --path /webhooks/postmark
No account required. Provides local tunnel + web UI for inspecting requests.
Resources
- overview.md - What Postmark webhooks are, common event types
- setup.md - Configure webhooks in Postmark dashboard
- verification.md - Authentication methods and security best practices
- examples/ - Complete implementations for Express, Next.js, and FastAPI
Recommended: webhook-handler-patterns
For production-ready webhook handling, also install the webhook-handler-patterns skill:
Related Skills
1---2name: postmark-webhooks3description: Receive and process Postmark webhooks. Use when setting up Postmark webhook handlers, handling email delivery events, processing bounces, opens, clicks, spam complaints, or subscription changes.4license: MIT5---6
7# Postmark Webhooks
8
9## When to Use This Skill
10
11- Setting up Postmark webhook handlers for email event tracking
12- Processing email delivery events (bounce, delivered, open, click)
13- Handling spam complaints and subscription changes
14- Implementing email engagement analytics
15- Troubleshooting webhook authentication issues
16
17## Essential Code
18
19### Authentication
20
21Postmark does NOT use signature verification. Instead, webhooks are authenticated by including credentials in the webhook URL itself.
22
23```javascript
24// Express - Basic Auth in URL
25// Configure webhook URL in Postmark as:
26// https://username:password@yourdomain.com/webhooks/postmark
27
28app.post('/webhooks/postmark', express.json(), (req, res) => {
29 // Basic auth is handled by your web server or proxy
30 // Additional validation can check expected payload structure
31
32 const event = req.body;
33
34 // Validate expected fields exist
35 if (!event.RecordType || !event.MessageID) {
36 return res.status(400).send('Invalid payload structure');
37 }
38
39 // Process event
40 console.log(`Received ${event.RecordType} event for ${event.Email}`);
41
42 res.sendStatus(200);
43});
44
45// Alternative: Token in URL
46// Configure webhook URL as:
47// https://yourdomain.com/webhooks/postmark?token=your-secret-token
48
49app.post('/webhooks/postmark', express.json(), (req, res) => {
50 const token = req.query.token;
51
52 if (token !== process.env.POSTMARK_WEBHOOK_TOKEN) {
53 return res.status(401).send('Unauthorized');
54 }
55
56 const event = req.body;
57 console.log(`Received ${event.RecordType} event`);
58
59 res.sendStatus(200);
60});
61```
62
63### Handling Multiple Events
64
65```javascript
66// Postmark sends one event per request (not batched)
67app.post('/webhooks/postmark', express.json(), (req, res) => {
68 const event = req.body;
69
70 switch (event.RecordType) {
71 case 'Bounce':
72 console.log(`Bounce: ${event.Email} - ${event.Type} - ${event.Description}`);
73 // Update contact as undeliverable
74 break;
75
76 case 'SpamComplaint':
77 console.log(`Spam complaint: ${event.Email}`);
78 // Remove from mailing list
79 break;
80
81 case 'Open':
82 console.log(`Email opened: ${event.Email} at ${event.ReceivedAt}`);
83 // Track engagement
84 break;
85
86 case 'Click':
87 console.log(`Link clicked: ${event.Email} - ${event.OriginalLink}`);
88 // Track click-through rate
89 break;
90
91 case 'Delivery':
92 console.log(`Delivered: ${event.Email} at ${event.DeliveredAt}`);
93 // Confirm delivery
94 break;
95
96 case 'SubscriptionChange':
97 console.log(`Subscription change: ${event.Email} - ${event.ChangedAt}`);
98 // Update subscription preferences
99 break;
100
101 case 'Inbound':
102 console.log(`Inbound email from: ${event.Email} - Subject: ${event.Subject}`);
103 // Process incoming email
104 break;
105
106 case 'SMTP API Error':
107 console.log(`SMTP API error: ${event.Email} - ${event.Error}`);
108 // Handle API error, maybe retry
109 break;
110
111 default:
112 console.log(`Unknown event type: ${event.RecordType}`);
113 }
114
115 res.sendStatus(200);
116});
117```
118
119## Common Event Types
120
121| Event | RecordType | Description | Key Fields |
122|-------|------------|-------------|------------|
123| Bounce | `Bounce` | Hard/soft bounce or blocked email | Email, Type, TypeCode, Description |
124| Spam Complaint | `SpamComplaint` | Recipient marked as spam | Email, BouncedAt |
125| Open | `Open` | Email opened (requires open tracking) | Email, ReceivedAt, Platform, UserAgent |
126| Click | `Click` | Link clicked (requires click tracking) | Email, ClickedAt, OriginalLink |
127| Delivery | `Delivery` | Successfully delivered | Email, DeliveredAt, Details |
128| Subscription Change | `SubscriptionChange` | Unsubscribe/resubscribe | Email, ChangedAt, SuppressionReason |
129| Inbound | `Inbound` | Incoming email received | Email, FromFull, Subject, TextBody, HtmlBody |
130| SMTP API Error | `SMTP API Error` | SMTP API call failed | Email, Error, ErrorCode, MessageID |
131
132## Environment Variables
133
134```bash
135# For token-based authentication
136POSTMARK_WEBHOOK_TOKEN="your-secret-token-here"
137
138# For basic auth (if not using URL-embedded credentials)
139WEBHOOK_USERNAME="your-username"
140WEBHOOK_PASSWORD="your-password"
141```
142
143## Security Best Practices
144
1451. **Always use HTTPS** - Never configure webhooks with HTTP URLs
1462. **Use strong credentials** - Generate long, random tokens or passwords
1473. **Validate payload structure** - Check for expected fields before processing
1484. **Implement IP allowlisting** - Postmark publishes their IP ranges
1495. **Consider using a webhook gateway** - Like Hookdeck for additional security layers
150
151## Local Development
152
153For local webhook testing, use Hookdeck CLI:
154
155```bash
156npx hookdeck-cli listen 3000 postmark --path /webhooks/postmark
157```
158
159No account required. Provides local tunnel + web UI for inspecting requests.
160
161## Resources
162
163- [overview.md](references/overview.md) - What Postmark webhooks are, common event types
164- [setup.md](references/setup.md) - Configure webhooks in Postmark dashboard
165- [verification.md](references/verification.md) - Authentication methods and security best practices
166- [examples/](examples/) - Complete implementations for Express, Next.js, and FastAPI
167
168## Recommended: webhook-handler-patterns
169
170For production-ready webhook handling, also install the webhook-handler-patterns skill:
171
172- [Handler sequence](https://github.com/hookdeck/webhook-skills/blob/main/skills/webhook-handler-patterns/references/handler-sequence.md) - Webhook processing flow
173- [Idempotency](https://github.com/hookdeck/webhook-skills/blob/main/skills/webhook-handler-patterns/references/idempotency.md) - Prevent duplicate processing
174- [Error handling](https://github.com/hookdeck/webhook-skills/blob/main/skills/webhook-handler-patterns/references/error-handling.md) - Graceful error recovery
175- [Retry logic](https://github.com/hookdeck/webhook-skills/blob/main/skills/webhook-handler-patterns/references/retry-logic.md) - Handle transient failures
176
177## Related Skills
178
179- [sendgrid-webhooks](https://github.com/hookdeck/webhook-skills/tree/main/skills/sendgrid-webhooks) - SendGrid webhook handling with ECDSA verification
180- [resend-webhooks](https://github.com/hookdeck/webhook-skills/tree/main/skills/resend-webhooks) - Resend webhook handling with Svix signatures
181- [stripe-webhooks](https://github.com/hookdeck/webhook-skills/tree/main/skills/stripe-webhooks) - Stripe webhook handling with HMAC-SHA256
182- [webhook-handler-patterns](https://github.com/hookdeck/webhook-skills/tree/main/skills/webhook-handler-patterns) - Idempotency, error handling, retry logic
183- [hookdeck-event-gateway](https://github.com/hookdeck/webhook-skills/tree/main/skills/hookdeck-event-gateway) - Production webhook infrastructure