Skip to content

Repository files navigation

MailKite NestJS starter

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.

Run it

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:dev

Open 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"] }

Required environment variables

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.

How it's wired

  • src/mail/mail.module.tsMailerModule.forRoot({ transport: mailkiteTransport({ apiKey }) }). mailkiteTransport(...) returns a nodemailer Transport object, which is exactly what MailerModule's transport option accepts — no adapter code required.
  • src/mail/mail.controller.tsPOST /mail/send validates the body (class-validator DTO) and calls the injected MailerService.sendMail(). The resolved value is nodemailer-mailkite-transport's MailKiteSentMessageInfo ({ messageId, id, status, accepted, rejected, envelope }).
  • public/index.html — a dependency-free fetch-based form served as a static asset (app.useStaticAssets in src/main.ts), since NestJS itself is API-first and has no view layer of its own.

Build

npm run build   # nest build -> dist/
npm run start:prod

Local package reference

This 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").

About

Runnable NestJS starter demonstrating MailKite via nodemailer-mailkite-transport

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages