Email Service
The Email Service component provides a production-ready solution for sending emails in Servercn using nodemailer. It supports multiple email providers including Gmail, SMTP servers, SendGrid, and more.
Installation Guide
Install this component using the following command:
npx servercn-cli add email-servicePrerequisites
Gmail Setup (Recommended for Development)
- Enable 2-Step Verification on your Google Account
- Generate an App Password:
- Go to Google Account → Security → 2-Step Verification → App passwords
- Create a new app password for "Mail"
- Copy the generated password
Environment Variables
Add the following to your .env file:
SMTP Server
Resend
Mailtrap
Basic Implementation
1. Nodemailer with SMTP
Nodemailer SMTP Configuration
MVC Path: src/configs/nodemailer.ts
Feature Path: src/shared/configs/nodemailer.ts
Send Email Function
MVC Path: src/utils/send-mail.ts
Feature Path: src/shared/utils/send-mail.ts
2. Resend
Resend configuration
MVC Path: src/configs/resend.ts
Feature Path: src/shared/configs/resend.ts
Send Email Function
MVC Path: src/utils/send-mail.ts
Feature Path: src/shared/utils/send-mail.ts
3. Mailtrap
Mailtrap configuration
MVC Path: src/configs/mailtrap.ts
Feature Path: src/shared/configs/mailtrap.ts
Send Email Function
MVC Path: src/utils/send-mail.ts
Feature Path: src/shared/utils/send-mail.ts