Best practices for email security
Learn how to secure your Mailpipe integration with API key management, webhook verification, and encryption best practices.
Never expose API keys in client-side code
API keys should only be used in server-side code. For browser/client use, use Supabase session tokens instead.
mp_test_* keys for development and staging.gitignore and use .env.localRotate your API keys regularly, especially if you suspect a key has been compromised:
We recommend rotating keys every 90 days as a security best practice.
Always verify webhook signatures to ensure requests originate from Mailpipe:
import crypto from 'crypto';
function verifyWebhookSignature(
payload: string,
signature: string,
secret: string
): boolean {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expected)
);
}
// In your webhook handler:
app.post('/webhooks/mailpipe', (req, res) => {
const signature = req.headers['x-mailpipe-signature'];
const isValid = verifyWebhookSignature(
JSON.stringify(req.body),
signature,
process.env.MAILPIPE_WEBHOOK_SECRET
);
if (!isValid) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process the webhook...
});