adeel-mail-js
v1.0.9
Published
A lightweight SMTP mail server provider compatible with Nodemailer for sending transactional emails.
Maintainers
Readme
Adeel Mail
A lightweight SMTP mail helper built on top of Nodemailer. adeelMail provides a simple class-based interface to configure an SMTP transporter and send transactional emails.
Files of interest:
Overview
Create an instance of adeelMail with SMTP configuration (host, port, user, pass). Call mail() to obtain an object with a send async method to send emails.
Constructor parameters
Use the constructor like this:
new adeelMail({ host, port, secure = false, user, pass, globals = { from: "" } })host(string) — SMTP server host (required)port(number) — SMTP port (required)secure(boolean) — Use TLS/SSL (default:false)user(string) — SMTP username (required)pass(string) — SMTP password (required)globals(object) — global options, e.g.{ from: "[email protected]" }
If any required parameter is missing, the constructor sets an internal error and mail() will not return a usable sender.
Sending mail
Call mail() to get the sender object, then use send:
const instance = new adeelMail({...});
const mail = instance.mail();
await mail.send({ from, to, subject, text, html });send parameters:
from(string) — sender address; falls back toglobals.fromif not providedto(string) — recipient address (required)subject(string) — email subject (default:Hello From Adeel)text(string) — plain-text body (default:Hello, adeelMail)html(string) — HTML body (default: empty)
If to is missing, send throws an Error: "'to' is required.".
Return value
On success send returns a simple result object:
{
success: true,
email: { from, to }
}Note: the underlying nodemailer result from transporter.sendMail() is awaited inside send, but the exported wrapper returns a minimal success payload.
Example
The example in examples/provider/booking.mail.js:
import { adeelMail } from "../../src/index.js";
const bookingInit = new adeelMail({
host: "smtp.domain.com",
port: 465,
secure: true,
user: "[email protected]",
pass: "******",
globals: { from: "[email protected]" }
});
const booking = bookingInit.mail();
await booking?.send({ to: "[email protected]" });Dependencies
nodemailer(already declared inpackage.json)
Best practices
- Do not hard-code credentials in source. Use environment variables or a
.envfile. - Always
awaitthe asyncsendcall to catch errors. - Validate required constructor fields before creating the instance.
