Overview
Email notifications are triggered by event listeners that respond to status change events published by the supervisor. When a monitored URL’s status changes, an email is sent to the configured contact address. Notification triggers:- URL goes from healthy to unhealthy (downtime alert)
- URL recovers from unhealthy to healthy (recovery notification)
- First check result for a new URL
SMTP configuration
Configure SMTP settings in your.env file:
.env
Environment variables
Sender email address that appears in the “From” field of notification emails.Examples:
[email protected]- Dedicated notifications address[email protected]- Company alerts address[email protected]- No-reply address
Ensure this address is authorized to send emails through your SMTP provider. Some providers require sender verification.
SMTP server hostname.Common SMTP providers:
- SendGrid:
smtp.sendgrid.net - Mailgun:
smtp.mailgun.org - Gmail:
smtp.gmail.com - AWS SES:
email-smtp.us-east-1.amazonaws.com - Mailtrap (dev/testing):
sandbox.smtp.mailtrap.io
SMTP server port number.Common ports:
587- SMTP with STARTTLS (recommended for production)465- SMTP over SSL/TLS2525- Alternative port (used by Mailtrap and some providers)25- Standard SMTP (often blocked by ISPs, not recommended)
SMTP authentication username.Provider-specific notes:
- SendGrid: Use
apikeyas the username - Mailgun: Use your Mailgun SMTP username
- Gmail: Use your full Gmail address
- AWS SES: Use your SMTP credentials username
SMTP authentication password or API key.Provider-specific notes:
- SendGrid: Use your SendGrid API key
- Mailgun: Use your Mailgun SMTP password
- Gmail: Use an app-specific password (not your account password)
- AWS SES: Use your SMTP credentials password
Email implementation
Watchdog uses thegopkg.in/mail.v2 package for sending emails:
- Multiple recipients support
- Custom subject and content
- Configurable content type (HTML or plain text)
- Automatic SMTP connection management
- Error handling and logging
Configuring recipient emails
When adding a URL to monitor, specify the contact email for notifications:You can use the same contact email for multiple URLs, or set up distribution lists (e.g.,
[email protected]) to notify multiple people.SMTP provider setup
SendGrid
SendGrid
Steps:Pricing: Free tier includes 100 emails/day
- Create a SendGrid account at sendgrid.com
- Generate an API key:
- Go to Settings → API Keys
- Click “Create API Key”
- Select “Restricted Access” and enable “Mail Send”
- Verify your sender domain or single sender email
- Configure your
.env:
Mailgun
Mailgun
Steps:Pricing: Free tier includes 5,000 emails/month for 3 months
- Create a Mailgun account at mailgun.com
- Add and verify your domain
- Get your SMTP credentials from Settings → SMTP
- Configure your
.env:
Gmail
Gmail
Steps:
- Enable 2-factor authentication on your Google account
- Generate an app-specific password:
- Go to myaccount.google.com
- Security → 2-Step Verification → App passwords
- Generate password for “Mail”
- Configure your
.env:
AWS SES
AWS SES
Steps:Pricing: $0.10 per 1,000 emails, includes 62,000 free emails/month on AWS Free Tier
- Create an AWS account and enable SES in your region
- Verify your sender email or domain:
- Go to SES → Verified identities
- Add and verify your email/domain
- Request production access (by default, SES starts in sandbox mode)
- Create SMTP credentials:
- Go to SES → SMTP settings
- Click “Create SMTP Credentials”
- Configure your
.env:
Mailtrap (Development/Testing)
Mailtrap (Development/Testing)
Steps:
- Create a Mailtrap account at mailtrap.io
- Create an inbox (or use the default one)
- Get SMTP credentials from inbox settings
- Configure your
.env:
Mailtrap captures emails instead of sending them to recipients. Perfect for development and testing without risking sending test emails to real users.
Testing email configuration
Verify your SMTP settings are working correctly:Start the guard
Start the Watchdog monitoring service:The first check will trigger a notification email.
Verify email delivery
Check your inbox (or Mailtrap inbox for testing) for the notification email.If using a dev SMTP provider like Mailtrap, verify the email appears in the inbox dashboard.
Customizing email templates
TheSendEmail function accepts a SendEmailConfig with customizable content:
text/plain- Plain text emailstext/html- HTML emails with formatting
To customize notification templates, modify the event listener code in
events/listeners/ that calls SendEmail() in response to status change events.Notification architecture
Email notifications are triggered by the event-driven architecture:- Child workers perform HTTP checks and send results to supervisor
- Supervisor evaluates results and detects status changes
- Supervisor publishes
ping.successfulorping.unsuccessfulevents - Email listener subscribes to these events
- On status change, listener calls
SendEmail()with notification details - SMTP client sends email to configured recipient
Troubleshooting
SMTP authentication failed
SMTP authentication failed
Symptoms:
SMTP AUTH failed or 535 Authentication failedSolutions:- Verify
MAIL_USERNAMEandMAIL_PASSWORDare correct - For Gmail, ensure you’re using an app-specific password, not your account password
- Check if your SMTP provider requires sender verification
- Verify your account is not suspended or has exceeded quotas
Connection timeout or refused
Connection timeout or refused
Symptoms:
dial tcp: connect: connection refused or timeout errorsSolutions:- Verify
MAIL_HOSTandMAIL_PORTare correct - Check firewall rules allow outbound connections on the SMTP port
- Try alternative ports (587, 465, 2525)
- Verify your hosting provider doesn’t block SMTP connections
Emails not delivered (no errors)
Emails not delivered (no errors)
Symptoms:
SendEmail() succeeds but recipients don’t receive emailsSolutions:- Check recipient spam/junk folders
- Verify sender domain has SPF and DKIM records configured
- Check SMTP provider’s delivery logs for bounces
- Verify
MAIL_FROM_ADDRESSis authorized by your provider - Check if recipient email addresses are valid
SSL/TLS errors
SSL/TLS errors
Symptoms:
x509: certificate signed by unknown authoritySolutions:- Ensure you’re using the correct port for your encryption method:
- Port 587 uses STARTTLS (encryption after connection)
- Port 465 uses implicit SSL/TLS (encrypted from start)
- For self-signed certificates (development only), you may need to disable certificate verification
- Update your system’s CA certificates:
sudo update-ca-certificates
Rate limiting errors
Rate limiting errors
Symptoms:
550 Rate limit exceeded or 429 Too Many RequestsSolutions:- Reduce monitoring frequency for URLs
- Implement email throttling or batching
- Upgrade your SMTP provider plan
- Use separate SMTP accounts for different environments (dev/staging/prod)
Best practices
Use transactional email providers
Use dedicated transactional email services (SendGrid, Mailgun, AWS SES) instead of personal email accounts for better deliverability and reliability.
Configure sender authentication
Set up SPF, DKIM, and DMARC records for your sending domain to improve email deliverability and prevent spoofing:
Monitor email delivery
Track email delivery success rates and bounce rates using your SMTP provider’s dashboard.Consider implementing retry logic for failed email sends.
Separate environments
Use different SMTP configurations for development, staging, and production:
- Development: Mailtrap or similar email capture service
- Staging: Separate SMTP account with test recipient lists
- Production: Production SMTP account with real recipients
Advanced configuration
Custom email content
To customize notification email content, modify the event listener that callsSendEmail():