Overview
BillBuddy uses email notifications to send settlement summaries to group members after expenses are settled. The application uses Web3Forms, a simple email API service, to handle email delivery.While the package.json includes Nodemailer as a dependency, the current implementation uses Web3Forms for email delivery.
Email Service Setup
Web3Forms Configuration
BillBuddy uses Web3Forms for sending emails. Web3Forms provides a simple API without requiring SMTP configuration.Getting Started
- Visit Web3Forms
- Sign up for a free account
- Create a new access key from your dashboard
- Add the access key to your environment variables
Environment Variable
Your Web3Forms access key for sending emails through their API.
.env
Email Implementation
The email functionality is implemented in thebackend/utils/email.js file:
backend/utils/email.js
Email Parameters
Web3Forms API Parameters
Your Web3Forms access key from the environment variables.
Email subject line. Dynamically generated with the group name.Example:
Settlement Summary for Weekend TripThe sender name displayed in the recipient’s inbox.
The sender email address. This is a display address and doesn’t need to exist.
Comma-separated list of recipient email addresses. All group members receive the settlement summary.
HTML email body containing the settlement summary with balances for all group members.
Email address for replies. Set to a no-reply address by default.
Settlement Email Template
The settlement email includes:- Header: Group name in the subject and body
- Final Balances: List showing who owes money and who is owed
- Footer: Closing message
Email Format
Example Email
Triggering Settlement Emails
Emails are automatically sent when a group settlement is processed through the settlements API:backend/routes/settlements.js
The
sendEmail parameter controls whether emails are sent during settlement. This allows flexibility for testing or dry-run settlements.Usage Example
To send settlement emails programmatically:Error Handling
The email service includes comprehensive error handling:Alternative: Nodemailer Configuration
If you prefer to use Nodemailer instead of Web3Forms, you can configure SMTP settings:Environment Variables for Nodemailer
.env
Nodemailer Implementation
Gmail Configuration
For Gmail, you need to use an App Password instead of your regular password. Enable 2-factor authentication and generate an app password from your Google Account settings.
Testing Email Functionality
Test Email Sending
Create a test script to verify email configuration:test-email.js
Troubleshooting
Email Not Sending
Problem: Emails are not being delivered Solution:- Verify
WEB3FORMS_ACCESS_KEYis set correctly - Check the Web3Forms dashboard for usage limits
- Ensure recipient email addresses are valid
- Check application logs for error messages
Invalid Access Key
Problem:401 Unauthorized or authentication errors
Solution:
- Verify the access key in your
.envfile - Generate a new access key from Web3Forms dashboard
- Restart the server after updating the key
Emails Going to Spam
Web3Forms handles email delivery infrastructure, but recipient mail servers may still flag emails as spam.
- Use a professional sender name
- Keep email content clear and concise
- Avoid spam trigger words
- Consider using a custom domain for
from_email
Rate Limiting
Web3Forms has rate limits based on your plan:- Free Plan: 250 emails per month
- Paid Plans: Higher limits available
Best Practices
- Error Handling: Always wrap email sending in try-catch blocks
- Logging: Log email send attempts and failures for debugging
- Testing: Test email functionality in development before deploying
- Monitoring: Track email delivery success rates
- Fallback: Consider implementing a fallback notification method (SMS, in-app notifications)
- Templates: Use email templates for consistent formatting
- Personalization: Include recipient names and relevant details
Security Considerations
- Store access keys in environment variables only
- Rotate access keys periodically
- Monitor usage for unusual activity
- Validate email addresses before sending
- Sanitize user input in email content to prevent injection attacks