simple-mail-server-node
v1.1.0
Published
Tiny helper around Nodemailer for simple template-based sending with minimal setup
Maintainers
Readme
Simple Mail Server
A tiny helper around Nodemailer for sending template-based emails with minimal configuration. Designed to simplify sending emails in Node.js projects.
Features
- Simple configuration via environment variables
- Supports SMTP or service-based email (e.g., Gmail)
- Built-in email templates (welcome email example)
- Custom HTML email support
- Easy to integrate into any Node.js project
- Optional transporter verification at startup
Installation
npm install simple-mail-server-nodeEnvironment Configuration
Create a .env file in the root of your project:
[email protected]
MAIL_PASS=your_app_password
# Optional settings:
MAIL_SERVICE=gmail
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_SECURE=false
MAIL_VERIFY=true
MAIL_FROM="My App <[email protected]>"Notes:
MAIL_USERandMAIL_PASSare required for authentication.MAIL_SERVICEcan begmail,yahoo, etc., for common email providers.MAIL_HOSTis required if you are using a custom SMTP server.MAIL_VERIFY=truewill check the transporter connection at startup (recommended for debugging).
Usage
1. Sending an email with a template
const { sendMail } = require('simple-mail-server-node');
(async () => {
const result = await sendMail({
to: "[email protected]",
subject: "Welcome!",
templateName: "welcome", // use built-in template
variables: { username: "John Doe" }, // template variables
});
console.log(result);
})();2. Sending an email with custom HTML
const { sendMail } = require('simple-mail-server-node');
(async () => {
const result = await sendMail({
to: "[email protected]",
subject: "Custom Email",
customHtml: "<h1>Hello!</h1><p>This is a custom email.</p>"
});
console.log(result);
})();3. Overriding the sender email
const { sendMail } = require('simple-mail-server-node');
(async () => {
const result = await sendMail({
to: "[email protected]",
subject: "Custom Sender",
customHtml: "<p>Check out this email.</p>",
from: "Support <[email protected]>"
});
console.log(result);
})();Built-in Templates
Currently includes:
welcome: a simple welcome email template
Dependencies
License
MIT License © Md Shakil Hossain
Notes
- Make sure to use an App Password for Gmail if using
MAIL_SERVICE=gmail. - Always keep your
.envfile secure and do not commit credentials to GitHub.
