Skip to content

Versions & upgrading ​

@nestjs-modules/mailer has three documented major versions. This page tells you which one you are on, what each supports, what changed between them and how to upgrade. The docs for older versions stay online: v3 and v2.

Not sure which one you have? Run pnpm why @nestjs-modules/mailer (or npm ls @nestjs-modules/mailer) and look at the major version.

Support status ​

VersionStatusWhat it getsDocs
v4CurrentNew features, bug fixes and security fixesGuide
v3 (3.0.x)MaintenanceSecurity fixes for now; no new featuresv3 docs
v2 (2.3.x)End of lifeNothing, including security fixesv2 docs

New projects should start on v4. If you are on v2, upgrade: it misses the security fixes of 3.0.

Requirements ​

v4v3v2
NestJS11 – 127 – 127 – 11
Node.js20 or later; NestJS 12 needs >= 20.19 (or >= 22.12)20 or later; NestJS 12 needs >= 20.19 (or >= 22.12)No constraint declared; tested on 20, 22, 24
nodemailer>= 8.0.5>= 8.0.5>= 8.0.5 (2.3.10)
Template enginesOptional peers, install your ownOptional peers, install your ownInstalled automatically
ejs / pug floor>= 3.1.10 / >= 3.0.3>= 3.1.10 / >= 3.0.3>= 3.1.2 / >= 3.0.1

Install ​

Pin the major you want. A plain pnpm add @nestjs-modules/mailer installs the latest (v4).

bash
pnpm add @nestjs-modules/mailer@^4 nodemailer
bash
pnpm add @nestjs-modules/mailer@^3 nodemailer
bash
pnpm add @nestjs-modules/mailer@^2 nodemailer
bash
npm install @nestjs-modules/mailer@^4 nodemailer   # or @^3, @^2
bash
yarn add @nestjs-modules/mailer@^4 nodemailer      # or @^3, @^2

With v3 and v4, also install the template engine your adapter uses, for example pnpm add handlebars.

What changed ​

The MailerModule.forRoot() / sendMail() API is the same in all three versions. The differences are in defaults and in what is available:

v2v3v4
Template engine installationAll installed automaticallyInstall the one you useInstall the one you use
Inline html {{key}}Inserted as-isHTML-escaped ({{{key}}} for raw)HTML-escaped, plus the html tag
Remote stylesheets in CSS inliningFetchedNot fetched (loadRemoteStylesheets)Not fetched
Local stylesheets and textTemplateAny pathOnly inside template.dir / cssBaseUrlOnly inside template.dir / cssBaseUrl
i18n localeUsed as givenValidated (BCP 47-like)Validated, falls back es-CO → es
Pug compiler optionsFrom template.options and contexttemplate.options onlytemplate.options only
Health indicator on failureReturns the error messageLogs it, returns down onlyLogs it, returns down only
Mail classes (send(WelcomeMail, …))NoNoYes
RetriesNone, one attemptNone, one attempt3 attempts with backoff by default (retry: false for v3 behavior)
Failover, AbortSignal, idempotencyKeyNoNoYes
ErrorsRaw nodemailer errorsRaw nodemailer errorsTyped MailerError subclasses (wrapErrors: false for raw)
Plain-text part from HTMLNoNoYes (textFromHtml: false to opt out)
Message validationNoNoYes (validate: false to opt out)
MailerTestModule transportnodemailer streamTransportnodemailer streamTransportTestMailbox with assertions
Email previewspreview option (preview-email)preview option (preview-email)preview option and MailerPreviewModule at /_mailer
Dev transports (FileTransport, LogTransport)NoNoYes
Delivery rules (intercept, suppress, unsubscribe)NoNoYes
@OnEvent() listeners with @nestjs/event-emitterNever firedNever firedFire; plus events$, RETRY, FAILOVER, SUPPRESSED (events)
Interop with @nestjs/mailNoNoYes
Transactional outbox (@nestjs/outbox)NoNoYes
HTTP transports (Resend, Postmark, SendGrid, SES, Mailgun, Brevo)NoNoYes
BullMQ queueYesYesYes, plus schedule(), concurrency, permanent failures fail the job
NestJS 11YesYesYes
NestJS 12NoYesYes

Upgrade path ​

Upgrade one major at a time, or apply both migration guides at once if you go from v2 to v4:

  1. v2 → v3: Migrating from v2 to v3. Install your template engine, switch trusted inline placeholders to {{{key}}}, check remote or out-of-directory stylesheets, move Pug compiler options to template.options. Docs: v3.
  2. v3 → v4: Migrating to v4. Retries are on by default, errors are typed, messages are validated and get a plain-text part. Each new default has a one-line opt-out. Docs: v4 guide.

The release notes for every version are in the changelog.

Released under the MIT License.