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.
async function handleWebhook(events) { // Store raw events await storeRawEvents(events); // Process each event for (const event of events) { try { await processEvent(event); } catch (error) { console.error(`Error processing event ${event.sg_event_id}:`, error); // Continue processing other events } }}
# SendGrid API Key (for sending emails)SENDGRID_API_KEY=SG.xxxxxxxxxxxxxxxxxxxx# Webhook Verification KeySENDGRID_WEBHOOK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...-----END PUBLIC KEY-----"# OptionalSENDGRID_FROM_EMAIL=noreply@example.comSENDGRID_TEMPLATE_ID=d-xxxxxxxxxxxxxxxxxxxxx