Agent skill

Postmark Webhooks Skill

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.

Install this skill

npx skills add hookdeck/webhook-skills --skill 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 with credentials you configure on the webhook: Basic Auth or a token in the URL (shown below), or a custom header set with HttpHeaders (see references/verification.md).

// 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 (Inbound payloads have no RecordType).
  // SubscriptionChange can have MessageID: null, and a 4xx makes Postmark drop the event.
  const recordType = event.RecordType || (event.FromFull ? 'Inbound' : undefined);
  if (!recordType || (recordType !== 'SubscriptionChange' && !event.MessageID)) {
    return res.status(400).send('Invalid payload structure');
  }

  // Process event
  console.log(`Received ${event.RecordType || 'Inbound'} event for message ${event.MessageID}`);

  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;
  const expectedToken = process.env.POSTMARK_WEBHOOK_TOKEN;

  // Fail closed: never accept a request when no token is configured
  if (!expectedToken || token !== expectedToken) {
    return res.status(401).send('Unauthorized');
  }

  const event = req.body;
  console.log(`Received ${event.RecordType || 'Inbound'} 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;

  // Inbound webhooks have no RecordType, so identify them by FromFull
  const recordType = event.RecordType || (event.FromFull ? 'Inbound' : undefined);

  switch (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.Recipient} at ${event.ReceivedAt}`);
      // Track engagement
      break;

    case 'Click':
      console.log(`Link clicked: ${event.Recipient} - ${event.OriginalLink}`);
      // Track click-through rate
      break;

    case 'Delivery':
      console.log(`Delivered: ${event.Recipient} at ${event.DeliveredAt}`);
      // Confirm delivery
      break;

    case 'SubscriptionChange':
      console.log(`Subscription change: ${event.Recipient} - ${event.ChangedAt}`);
      // Update subscription preferences
      break;

    case 'Inbound':
      console.log(`Inbound email from: ${event.From} - Subject: ${event.Subject}`);
      // Process incoming email
      break;

    case 'SMTP API Error':
      // Postmark publishes no sample payload for this webhook: check these
      // names against a real delivery
      console.log(`SMTP API error: ${event.Email} - ${event.Error}`);
      // Handle API error, maybe retry
      break;

    default:
      console.log(`Unknown event type: ${recordType}`);
  }

  res.sendStatus(200);
});

Common Event Types

EventRecordTypeDescriptionKey Fields
BounceBounceHard/soft bounce or blocked emailEmail, Type, TypeCode, Description
Spam ComplaintSpamComplaintRecipient marked as spamEmail, BouncedAt
OpenOpenEmail opened (requires open tracking)Recipient, ReceivedAt, Platform, UserAgent
ClickClickLink clicked (requires click tracking)Recipient, ReceivedAt, OriginalLink
DeliveryDeliverySuccessfully deliveredRecipient, DeliveredAt, Details
Subscription ChangeSubscriptionChangeUnsubscribe/resubscribeRecipient, ChangedAt, SuppressionReason
InboundNoneIncoming email receivedFrom, FromFull, Subject, TextBody, HtmlBody
SMTP API ErrorSMTP API ErrorSMTP API call failedEmail, Error, ErrorCode, MessageID

Inbound payloads have no RecordType, so identify them by FromFull. Postmark publishes no sample payload for SMTP API Error, so check that row's RecordType and fields against a real delivery.

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

  1. Always use HTTPS - Never configure webhooks with HTTP URLs
  2. Use strong credentials - Generate long, random tokens or passwords
  3. Validate payload structure - Check for expected fields before processing
  4. Implement IP allowlisting - Postmark publishes their IP ranges
  5. 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

Repository

hookdeck/webhook-skills

v0.1.0 · MIT · Updated Aug 1, 2026

View on GitHub →