A runnable NestJS app that sends email through MailKite:
@nestjs-modules/mailer's MailerModule configured with
nodemailer-mailkite-transport, a
POST /mail/send controller endpoint, and a static test form at /.
No new MailKite-specific NestJS package is needed — see
docs/integrations/nestjs.md for why
direct @nestjs-modules/mailer configuration is the right amount of code here.
cd starters/nestjs
npm install
cp .env.example .env
# edit .env: set MAILKITE_API_KEY and MAIL_FROM to an address on a
# MailKite-verified domain (https://mailkite.dev/docs/domains)
npm run start:devOpen http://localhost:3000 for the test form, or call the endpoint directly:
curl -X POST http://localhost:3000/mail/send \
-H "Content-Type: application/json" \
-d '{"to":"ada@example.com","subject":"Hello from Nest","html":"<p>Hi!</p>"}'A successful response looks like:
{ "messageId": "msg_...", "status": "queued", "accepted": ["ada@example.com"] }| Variable | Required | Default | What |
|---|---|---|---|
MAILKITE_API_KEY |
yes | — | Your MailKite API key (mk_live_…). Dashboard → Settings → API key. |
MAIL_FROM |
no | "MailKite Starter" <hello@yourdomain.com> |
Default from header. Must be on a verified domain. |
PORT |
no | 3000 |
HTTP port the Nest app listens on. |
src/mail/mail.module.ts—MailerModule.forRoot({ transport: mailkiteTransport({ apiKey }) }).mailkiteTransport(...)returns a nodemailerTransportobject, which is exactly whatMailerModule'stransportoption accepts — no adapter code required.src/mail/mail.controller.ts—POST /mail/sendvalidates the body (class-validatorDTO) and calls the injectedMailerService.sendMail(). The resolved value isnodemailer-mailkite-transport'sMailKiteSentMessageInfo({ messageId, id, status, accepted, rejected, envelope }).public/index.html— a dependency-free fetch-based form served as a static asset (app.useStaticAssetsinsrc/main.ts), since NestJS itself is API-first and has no view layer of its own.
npm run build # nest build -> dist/
npm run start:prodThis starter depends on the in-repo nodemailer-mailkite-transport package via
a file: reference (../../integrations/nodemailer-transport) since it isn't
published to npm yet in this checkout. Once published, swap the dependency in
package.json to a normal semver range (e.g. "^0.1.0").