A simple Node.js application that receives webhook notifications and sends emails via SMTP.
-
Copy the environment template and configure your SMTP settings:
cp .env.example .env
-
Edit
.envwith your SMTP credentials:SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_SECURE=false [email protected] SMTP_PASS=your-app-password [email protected] [email protected] PORT=3000 WEBHOOK_SECRET=your-secret-key -
Install dependencies:
npm install
-
Start the server:
npm start
Send a POST request to the webhook endpoint:
curl -X POST http://localhost:3000/webhook \
-H "Content-Type: application/json" \
-H "X-Webhook-Secret: your-secret-key" \
-d '{
"subject": "Test Notification",
"body": "This is a test email from the webhook."
}'| Field | Required | Description |
|---|---|---|
subject |
Yes* | Email subject line |
body |
Yes* | Plain text email body |
html |
No | HTML email body (optional) |
to |
No | Override default recipient |
*At least subject or body must be provided.
Authentication is disabled by default. To enable it, set WEBHOOK_SECRET in your .env file.
When enabled, include your secret in either:
- Header:
X-Webhook-Secret: your-secret - Query parameter:
?secret=your-secret
To disable authentication, leave WEBHOOK_SECRET empty or remove it.
GET /health- Health checkPOST /webhook- Main webhook endpoint
Common SMTP configurations:
Gmail (requires App Password):
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
Outlook/Hotmail:
SMTP_HOST=smtp-mail.outlook.com
SMTP_PORT=587
SMTP_SECURE=false
Custom SMTP:
SMTP_HOST=mail.yourdomain.com
SMTP_PORT=465
SMTP_SECURE=true