Natural Preference for Minification

    TypeScript icon, indicating that this package has built-in type declarations

    2.0.5 • Public • Published


    A NestJS library to generate emails via JSX and send them via AWS SES

    How it works

    The rendering is powered by mjml with a React wrapper.
    This allows email templates & components to be created in a typesafe way while having the complexities of email HTML handled by mjml.

    The generated HTML runs through html-to-text to automatically create a text version of the email.
    Where needed, this ouput can be customized with our <InText> and <HideInText> components.

    After that a MIME message is composed via emailjs.
    This merges the HTML, text, attachments, & headers (from, to, etc.) to a string.

    With the MIME message finalized it is sent to SES via their v3 SDK.
    Their SDK allows for automatic configuration; compared to SMTP which needs to be configured with an explicit server, username, and password.

    All of this is wrapped in an NestJS module for easy integration.

    There's also an open option to open rendered HTML in browser, which can be useful for development.


    Simple static

      from: '', // "Dev <>" format also works
      send: true, // Actually send email. It's assumed this is not always wanted aka dev.
      global: true, // Optionally allow EmailService to be used globally without importing module

    See EmailModuleOptions for all options.

    Async Configuration

    More complex setups can use async configuration (standard to NestJS packages)

    Factory function example

      useFactory: async (foo: FooService) => ({
        from: await foo.getFromAddress(),
      import: [FooService],

    Options class example

      useClass: EmailConfig,
      // or
      useExisting: EmailConfig,
    export class EmailConfig implements EmailOptionsFactory {
      async createEmailOptions() {
        return {
          from: '',


    Define a template

    import * as Mjml from '@seedcompany/nestjs-email/templates';
    import { Mjml as MjmlRoot } from 'mjml-react';
    import * as React from 'react';
    export function ForgotPassword({ name, url }: { name: string, url: string }) {
      return (
        <MjmlRoot lang="en">
            {/* Title also sets the subject */}
            <Mjml.Title>Forgot Password</Mjml.Title>
              <Mjml.Column padding={0}>
                <Mjml.Text fontSize={24}>
                  Hey {name}, passwords are hard
                  If you requested this, confirm the password change
                <Mjml.Button href={url}>CONFIRM</Mjml.Button>

    This is a single component to show the complete picture. In actual usage it makes more sense to break this up into smaller components, just like would be done with React UIs.

    For example, an <Email> wrapping component could be created to wrap Mjml root, Head, Body, setup theme, etc.

    A <Heading> component could turn the first section into a one liner.

    Call it

    import { Injectable } from '@nestjs/common';
    import { EmailService } from '@seedcompany/nestjs-email';
    import { ForgotPassword } from './forgot-password.template';
    export class UserService {
      constructor(private email: EmailService) {}
      async forgotPassword(emailAddress: string) {
        const user = await lookupByEmail(emailAddress);
        await, ForgotPassword, {
          // type safe parameters per template
          url: '',




    npm i @seedcompany/nestjs-email

    DownloadsWeekly Downloads






    Unpacked Size

    45.8 kB

    Total Files


    Last publish


    • michaelm220
    • carsonfull