Skip to content

Email Notifications

Rack Gateway sends email notifications for security events, user management actions, and system alerts using Postmark.

  • Security Alerts: Failed logins, MFA failures, rate limits
  • User Notifications: Welcome emails, role changes, account locks
  • Admin Alerts: User additions, suspicious activity
  • Async Processing: Background job queue for reliable delivery
  1. Sign up at https://postmarkapp.com
  2. Create a new server for Rack Gateway
  3. Copy the Server API Token
  4. Verify your sender domain
Terminal window
# Required
POSTMARK_API_KEY=your-server-api-token
POSTMARK_FROM_EMAIL=gateway@yourdomain.com
# Optional
POSTMARK_MESSAGE_STREAM=outbound # Default: outbound

After restarting the gateway, check logs for email configuration:

INFO: Email sender configured (Postmark)

Without Postmark configured:

INFO: Email sender configured (Noop - emails disabled)

Sent to the user when MFA verification fails.

FieldContent
SubjectFailed MFA Verification Attempt
ToUser email
ContentTime, IP address, user agent
Hello Alice,
We detected a failed multi-factor authentication attempt on your account.
Details:
- Time: 2024-01-15 10:30:00 UTC
- IP Address: 192.168.1.100
- User Agent: Mozilla/5.0...
If this wasn't you, please contact your administrator immediately.

Sent when a login attempt fails (after OAuth).

FieldContent
SubjectFailed Login Attempt
ToUser email
ContentTime, channel, status, IP, user agent

Sent when a user exceeds rate limits.

To User:

FieldContent
SubjectRate Limit Exceeded
ToUser email
ContentPath, time, IP address

To Admins:

FieldContent
SubjectRate Limit Exceeded - User {email}
ToAll admin users
ContentUser info, path, time, IP

Sent when a new user is added.

FieldContent
SubjectWelcome to {Rack} Rack Gateway
ToNew user email
ContentRoles, inviter, gateway URL
Hello Alice,
You have been added to the Production Rack Gateway by admin@example.com.
Your assigned roles: deployer, viewer
You can access the gateway at:
https://gateway.example.com
Please log in with your Google Workspace account to get started.
Welcome aboard!

Sent to all admins when a user is added.

FieldContent
SubjectNew User Added to {Rack} Rack Gateway: {email}
ToAll admin users (BCC)
ContentUser info, roles, creator, time

Sent when a user account is locked.

FieldContent
SubjectAccount Locked
ToLocked user email
ContentReason, contact instructions

Sent when an account is auto-locked due to MFA failures.

FieldContent
SubjectAccount Auto-Locked - Too Many MFA Failures
ToUser and admins
ContentFailure count, IP addresses, time

Email notifications use River for async processing:

Job KindDescription
email:security:failed_mfaFailed MFA notification
email:security:failed_loginFailed login notification
email:security:rate_limit_userRate limit user alert
email:security:rate_limit_adminRate limit admin alert
email:user:welcomeWelcome email
email:user:added_adminAdmin notification
email:user:lockedAccount locked
email:security:mfa_autolockMFA auto-lock alert
  • Jobs retry on failure
  • Exponential backoff
  • Max retries configurable

Check job status in gateway logs:

INFO: Email job completed: email:user:welcome
ERROR: Email job failed: postmark send failed: 401 Unauthorized

In development, emails can be logged instead of sent:

Terminal window
DEV_MODE=true
# or
DEV_EMAIL_LOG=true

Emails are logged to stdout:

DEBUG [email:summary] to=alice@example.com subject="Welcome to Production Rack Gateway"
DEBUG [email:body] text=... html=...

In development, emails are stored in memory for inspection:

// API endpoint for E2E tests
GET /api/v1/dev/emails
VariableRequiredDefaultDescription
POSTMARK_API_KEYYes-Postmark server API token
POSTMARK_FROM_EMAILYes-Verified sender email
POSTMARK_MESSAGE_STREAMNooutboundMessage stream name
DEV_EMAIL_LOGNofalseLog emails instead of sending

The gateway selects email sender based on configuration:

SenderBehavior
PostmarkSends via Postmark API
LoggerLogs to stdout (development)
NoopDoes nothing (silent)
  1. Verify configuration

    • Check POSTMARK_API_KEY is set
    • Check POSTMARK_FROM_EMAIL is set
    • Restart gateway after changes
  2. Check Postmark

    • Verify domain is verified
    • Check API token is valid
    • Review Postmark activity log
  3. Check gateway logs

    • Look for email job errors
    • Check for Postmark API errors

Causes:

  • Invalid API token
  • Token doesn’t match server
  • Server disabled

Resolution:

  • Regenerate Postmark API token
  • Verify using correct server token (not account token)

Causes:

  • Recipient email bounced previously
  • Recipient marked as complaint

Resolution:

  • Check Postmark suppressions list
  • Contact recipient to verify email

Resolution:

  • Verify sender domain with SPF/DKIM/DMARC
  • Use consistent “From” address
  • Avoid spam trigger words
  • Always verify your sender domain in Postmark
  • Configure SPF, DKIM, and DMARC records
  • Use a dedicated subdomain for gateway emails
  • Emails contain security-sensitive information
  • Never include passwords or tokens in emails
  • Keep notification details minimal
  • Rate limit security emails to prevent alert fatigue
  • Aggregate repeated events where possible
  • Don’t expose rate limiting in email content
  • Use a verified production domain
  • Monitor Postmark delivery rates
  • Set up Postmark alerts for bounces
  • Review suppression list regularly
  • Keep admin notification list current
  • Review security email patterns
  • Test email delivery regularly
  • Archive emails for compliance if required
  • Use clear, actionable subject lines
  • Include relevant context in body
  • Provide next steps or contact info
  • Keep emails concise