A simple Node.js microservice for sending emails using Express and Nodemailer. Designed for easy integration with other applications via a single POST endpoint.
- Send emails via a REST API
- CORS enabled for frontend integration
- Environment-based configuration for security (dotenv)
- Supports both development and production environments
- Node.js (v16 or newer recommended)
- pnpm (or npm/yarn)
-
Clone the repository:
git clone https://github.com/yourusername/mailer.git cd mailer -
Install dependencies:
pnpm install # or npm install -
Configure environment variables:
- Copy
.env.developmentand.env.productionand fill in your SMTP credentials. - Never commit your real credentials to git!
- Copy
-
Run in development:
node server.js
-
Run in production:
set NODE_ENV=production && node server.js
Send an email via the service.
Request Body (JSON):
{
"to": "recipient@example.com",
"subject": "Email Subject",
"html": "<b>Hello!</b>",
"appName": "YourAppName"
}
Response:
200 OKon success400if required fields are missing500on server error
- SMTP credentials are loaded from environment files using
dotenv. - All
.env*files are gitignored by default.
MIT