@lacspace/mailer
v1.0.4
Published
A tiny zero-dependency SMTP client for Node backends — send email over raw net/tls with STARTTLS, AUTH, attachments and provider presets (Hostinger, Gmail, Outlook, Zoho…). One-line setup.
Maintainers
Readme
@lacspace/mailer
Send email from Node with one line of setup — a zero-dependency SMTP client with provider presets.
Implements SMTP — STARTTLS,
AUTH LOGIN/PLAIN, MIME with attachments — directly over Node's built-innet/tls/crypto. No npm dependencies. Provider presets make Hostinger, Gmail, Outlook & friends a one-liner.
- 📮
send({ to, cc, bcc, subject, html, text, attachments, replyTo }) - 🏨 Presets: Hostinger, Gmail, Outlook/Office365, Zoho, Brevo, SMTP2GO, Mailgun, custom
- 🔒 Implicit TLS (465) and STARTTLS (587) · unicode subjects · bulletproof MIME
- 🌱
mailerFromEnv()readsSMTP_*— perfect for backends - ⚡ Zero dependencies · 🟢 Node 18+ (uses TCP sockets — server-side only)
Install
npm install @lacspace/mailer # or pnpm add / yarn add / bun addHostinger in one line
import { createMailer, presets } from "@lacspace/mailer";
const mail = createMailer(
presets.hostinger({ user: "[email protected]", pass: process.env.SMTP_PASS! }),
);
await mail.send({
to: "[email protected]",
subject: "Welcome to Lacspace ✨",
html: "<h1>You're in!</h1><p>Thanks for signing up.</p>",
text: "You're in! Thanks for signing up.",
});presets.hostinger → smtp.hostinger.com:465 (implicit TLS). Other presets:
presets.gmail({ user, pass }); // smtp.gmail.com:465 — use an App Password
presets.outlook({ user, pass }); // smtp.office365.com:587 (STARTTLS)
presets.zoho({ user, pass }); // smtp.zoho.com:465
presets.brevo({ user, pass }); // smtp-relay.brevo.com:587
presets.smtp2go({ user, pass });
presets.mailgun({ user, pass });From environment variables
import { createMailer, mailerFromEnv } from "@lacspace/mailer";
// reads SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_USER, SMTP_PASS, SMTP_FROM
const mail = createMailer(mailerFromEnv());Attachments, CC/BCC, reply-to
await mail.send({
from: "Lacspace <[email protected]>",
to: ["[email protected]", { name: "Bob", address: "[email protected]" }],
cc: "[email protected]",
bcc: "[email protected]",
replyTo: "[email protected]",
subject: "Your invoice",
html: "<p>Attached.</p>",
attachments: [
{ filename: "invoice.pdf", content: pdfBuffer, contentType: "application/pdf" },
{ filename: "notes.txt", content: "plain text content" },
],
});Pairs perfectly with
@lacspace/email-templates— build thehtmlyou pass tosend()@lacspace/email-validate— check the address before you send
import { otpEmail } from "@lacspace/email-templates";
await mail.send({ to, subject: "Your code", html: otpEmail({ code: "482913", brandName: "Lacspace" }) });Verify a connection
await mail.verify(); // resolves true if the server accepts the connection + credentialsCustom server (e.g. MailHog in dev)
createMailer({ host: "127.0.0.1", port: 1025, secure: false, ignoreTLS: true });API
| Member | Description |
| --- | --- |
| createMailer(config) | make a Mailer |
| mail.send(message) | send; returns { messageId, accepted, response } |
| mail.verify() | test connection + auth |
| mailerFromEnv(env?) | build config from SMTP_* vars |
| presets.* | one-line provider configs |
Node only. This package opens TCP/TLS sockets, so it does not run in browsers. For validating or composing emails in any runtime, use the isomorphic siblings below.
The Lacspace MailKit
| Package | For |
| --- | --- |
| @lacspace/mailer | Send email over SMTP (this package) |
| @lacspace/email-templates | Build responsive HTML emails |
| @lacspace/email-validate | Validate & normalize addresses |
| @lacspace/email-verify | MX + SMTP deliverability checks |
Licensing
This package is free under the Lacspace Free Licence — MIT-equivalent freedoms. Use it in personal and commercial projects at no cost; just keep the notice.
Not every Lacspace package is free. We also offer Commercial (paid), Client-specific, and Private (proprietary) packages under separate terms. See the full Lacspace Licence Centre.
Part of the Lacspace ecosystem — 35 zero-dependency, isomorphic TypeScript packages.
