@lockally/express
v0.1.0
Published
Official Lockally middleware for Express — send transactional email via Lockally with req.lockally.send(...).
Maintainers
Readme
@lockally/express
Official Lockally middleware for Express. app.use(lockally(...))
attaches a ready-to-use mailer at req.lockally so any route can send transactional
email in one call.
Install
npm install @lockally/expressUse
import express from "express";
import { lockally } from "@lockally/express";
const app = express();
app.use(lockally({ apiKey: process.env.LOCKALLY_API_KEY! }));
// lk_test_… runs in sandbox, lk_live_… sends real mail
// app.use(lockally({ apiKey, baseUrl: "https://api.lockally.com" })); // optional override
app.post("/signup", async (req, res) => {
await req.lockally.send({
from: "[email protected]",
to: "[email protected]",
subject: "Welcome",
text: "Thanks for signing up.",
html: "<b>Thanks for signing up.</b>",
replyTo: "[email protected]",
});
res.sendStatus(202);
});Send from outside a request (workers, cron) with the same config:
import { createMailer } from "@lockally/express";
const mailer = createMailer({ apiKey: process.env.LOCKALLY_API_KEY! });
await mailer.send({ from: "[email protected]", to: "[email protected]", subject: "Nightly report" });to/cc/bcc/replyTo accept a string or a string array. Attachments are
{ filename, content, contentType } where content is a Buffer, Uint8Array, or
string.
Mapping notes
- Reply-To is sent as a header (Lockally has no
reply_tofield). - Attachments are base64-encoded as
{ filename, contentType, contentBase64 }. - One
Idempotency-Keyis generated per send (24 h dedupe window).
License
MIT © Lockally
