A robust email service built with Hono, TypeScript, and PostgreSQL, designed to handle various types of email communications with customizable preferences and templates.
- Email type management with customizable templates
- User preferences for email frequency and types
- Email logging and tracking
- Error reporting system
- Admin interface for managing email settings
- Integration with Resend for email delivery
- Secure authentication and session management
- Database-driven configuration
- Framework: Hono (Node.js)
- Language: TypeScript
- Database: PostgreSQL with Drizzle ORM
- Email Provider: Resend
- Authentication: Custom session-based auth as well as API key-based authentication for backend services
- Package Manager: pnpm
- Code Quality: Biome for linting and formatting
- Templating Engine: Handlebars for email templating
- Node.js (Latest LTS version recommended)
- PostgreSQL database
- pnpm package manager
- Resend API key
- Stripe API key (
STRIPE_API_KEY) for payment-related emails
- Clone the repository:
git clone https://github.com/Meeting-BaaS/emails email-service
cd email-service- Install dependencies:
pnpm install- Create a
.envfile in the root directory with the following variables:
cp .env.example .envFill in the required environment variables in .env. Details about the expected values for each key is documented in .env.example.
DATABASE_URL: PostgreSQL connection stringRESEND_API_KEY: Resend API key for email deliveryRESEND_EMAIL_FROM: Sender email addressEMAIL_SERVICE_API_KEY: API key for backend service authenticationCRON_SECRET: Secret for cron job authenticationSTRIPE_API_KEY: Stripe API key for payment-related emailsNEXT_PUBLIC_BASE_DOMAIN: Base domain for external URLsNEXT_PUBLIC_SUPPORT_EMAIL: Support email address
- Set up the database:
pnpm db:generate # Generate database migrations
pnpm db:push # Apply migrations to the databasepnpm dev- Start development server with hot reloadpnpm build- Build the projectpnpm start- Start production serverpnpm db:generate- Generate database migrationspnpm db:push- Push database changespnpm db:studio- Open Drizzle Studio for database managementpnpm db:introspect- Introspect database schema
POST /account/verification-email- Send verification link emailPOST /account/password-reset-email- Send password reset emailPOST /account/insufficient-tokens- Send insufficient tokens notificationPOST /account/payment-activation- Send payment activation emailPOST /account/default-preferences- Save default email preferences
GET /types- List available email typesPOST /types- Create new email type
GET /preferences- Get user email preferencesPOST /preferences- Update user email preferencesGET /default-preferences- Get default email preferences
POST /resend- Resend the last sent email
GET /cron/usage-reports- Trigger usage reports cron jobGET /cron/internal-usage-reports- Trigger internal usage reports cron job
These jobs are Protected by CRON_SECRET. It is expected in the Authorization Header as "Bearer CRON_SECRET"
GET /admin/*- Admin interface endpoints
POST /error-report- Submit error reports
The service includes automated cron jobs for usage reports:
- Daily Reports: Runs at 10:00 AM daily
- Weekly Reports: Runs at 10:00 AM every Monday
- Monthly Reports: Runs at 10:00 AM on the 1st of each month
Cron jobs are configured in vercel.json and require the CRON_SECRET environment variable for authentication. The time denotes UTC time
The service supports various email types organized by domain:
usage-reports- Automated usage statisticsactivity-updates- User activity notifications
product-updates- Product feature updatesmaintenance- System maintenance notificationscompany-news- Company announcements
api-changes- API change notificationsdeveloper-resources- Developer-focused contentsecurity- Security-related announcements
billing- Billing and payment notificationsinsufficient_tokens_recording- Token balance alertspayment_activation- Payment method activation
- API Key Authentication: Backend routes protected with
EMAIL_SERVICE_API_KEY - Cron Secret: Cron endpoints protected with
CRON_SECRET - Security Headers: Implements comprehensive security headers middleware
- Request Logging: Detailed request and error logging
- Input Validation: Zod-based request validation
- Rate Limiting: Configurable cooldown periods for email resending
- Start the development server:
pnpm dev-
The server will be available at
http://localhost:3010 -
For database management, use Drizzle Studio:
pnpm db:studioThe service is configured for deployment on Vercel. The vercel.json file contains the necessary configuration including cron job schedules.
For production deployment, ensure all required environment variables are set in your Vercel project settings.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License