Skip to content

Webhooks

Webhooks allow MoMail to notify your application in real-time when events occur, such as receiving a new email or finishing semantic processing.

Retrieve all configured webhooks.

GET /v1/api/webhooks
{
"success": true,
"data": [
{
"webhook_id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret_masked": "whsec_****",
"active": true,
"createdAt": "2024-01-15T10:30:00.000Z"
}
]
}

Configure a new webhook endpoint.

POST /v1/api/webhooks
{
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret": "your_webhook_secret"
}
FieldTypeRequiredDescription
urlstringYesHTTPS URL to receive webhook payloads
eventsarrayYesList of events to subscribe to
secretstringNoSecret for verifying webhook signatures
EventDescription
email.receivedNew email received
email.processedEmail processing completed
api_key.createdNew API key created (not emitted yet)
{
"success": true,
"data": {
"webhook_id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret": "whsec_full_secret_shown_once",
"secret_masked": "whsec_****",
"active": true,
"created_at": "2024-01-15T10:30:00.000Z"
}
}

The full secret is returned only on create (and when you rotate via PATCH with a new secret). List responses include secret_masked only.

Retrieve details for a specific webhook.

GET /v1/api/webhooks/{id}
ParameterTypeRequiredDescription
idstringYesWebhook UUID
{
"success": true,
"data": {
"webhook_id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received"],
"secret_masked": "whsec_****",
"active": true,
"created_at": "2024-01-15T10:30:00.000Z"
}
}

Modify an existing webhook configuration.

PATCH /v1/api/webhooks/{id}

All fields are optional.

{
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"active": true,
"secret": "new_webhook_secret"
}
{
"success": true,
"data": {
"webhook_id": "wh_abc123",
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received", "email.processed"],
"secret_masked": "whsec_****",
"active": true,
"created_at": "2024-01-15T10:30:00.000Z"
}
}

When secret is updated, the response includes the new full secret once.

Remove a webhook configuration.

DELETE /v1/api/webhooks/{id}
{
"success": true,
"data": {
"message": "Webhook deleted successfully"
}
}
{
"event": "email.received",
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"email_id": "msg_abc123",
"message_id": "<[email protected]>",
"subject": "Project Update",
"from": "[email protected]",
"to": ["[email protected]"],
"date": "2024-01-15T10:29:55.000Z",
"mailbox_id": "mb_xyz789",
"domain": "yourdomain.com",
"has_attachments": true,
"thread_id": "thread_123"
}
}

MoMail signs webhook payloads using your webhook secret. Verify the signature to ensure the webhook came from MoMail.

X-MoMail-Signature: sha256={hex_signature}

The signature is HMAC-SHA256 of the raw JSON request body using your webhook secret.

const crypto = require('crypto');
function verifyWebhook(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload, 'utf8')
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expected)
);
}
// Express.js example
app.post('/webhooks/momail', (req, res) => {
const header = req.headers['x-momail-signature'] || '';
const signature = header.replace(/^sha256=/, '');
const payload = JSON.stringify(req.body);
const secret = process.env.WEBHOOK_SECRET;
if (!verifyWebhook(payload, signature, secret)) {
return res.status(401).send('Invalid signature');
}
// Process webhook
console.log('Received event:', req.body.event);
res.status(200).send('OK');
});

If your endpoint returns a non-2xx status code, MoMail will retry:

AttemptDelay
1Immediate
2500 ms
31000 ms

Failed deliveries are logged; the webhook remains active until you disable or delete it in the dashboard.

Terminal window
# Create webhook
curl -X POST https://momail.io/v1/api/webhooks \
-H "Authorization: Bearer your_key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.yourapp.com/webhooks/momail",
"events": ["email.received"],
"secret": "whsec_your_secret"
}'
# List webhooks
curl https://momail.io/v1/api/webhooks \
-H "Authorization: Bearer your_key"
# Delete webhook
curl -X DELETE https://momail.io/v1/api/webhooks/wh_abc123 \
-H "Authorization: Bearer your_key"