All Projects → yanarp → nestjs-mailer

yanarp / nestjs-mailer

Licence: MIT license
🌈 A simple implementation example with and without email-templates using mailer module for nest js built on top of nodemailer.

Programming Languages

Handlebars
879 projects
typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nestjs-mailer

Email Templates
📫 Create, preview, and send custom email templates for Node.js. Highly configurable and supports automatic inline CSS, stylesheets, embedded images and fonts, and much more!
Stars: ✭ 3,291 (+3913.41%)
Mutual labels:  pug, ejs, nodemailer
Vscode Deploy Reloaded
Recoded version of Visual Studio Code extension 'vs-deploy', which provides commands to deploy files to one or more destinations.
Stars: ✭ 129 (+57.32%)
Mutual labels:  pug, smtp
Vs Deploy
Visual Studio Code extension that provides commands to deploy files of a workspace to a destination.
Stars: ✭ 123 (+50%)
Mutual labels:  pug, smtp
Template.js
A javascript template engine, simple, easy & extras, support webpack, rollup, parcel, browserify, fis and gulp
Stars: ✭ 1,201 (+1364.63%)
Mutual labels:  handlebars, ejs
Davmail
DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
Stars: ✭ 250 (+204.88%)
Mutual labels:  smtp, outlook
Preview Email
Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!
Stars: ✭ 112 (+36.59%)
Mutual labels:  pug, nodemailer
Squirrelly
Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
Stars: ✭ 359 (+337.8%)
Mutual labels:  handlebars, pug
ESP-Mail-Client
⚡️Arduino Mail Client Library to send, read and get incoming mail notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.
Stars: ✭ 78 (-4.88%)
Mutual labels:  smtp, sender
aws-lambda-node-mailer
NodeJs code for Firing Email via AWS-Lambda and SES
Stars: ✭ 24 (-70.73%)
Mutual labels:  smtp, nodemailer
Smtp-cracker
[NEW] : Simple Mail Transfer Protocol (SMTP) CHECKER - CRACKER Tool V2
Stars: ✭ 67 (-18.29%)
Mutual labels:  smtp, sender
nest-mailman
📮 The mailer package for your NestJS Applications.
Stars: ✭ 161 (+96.34%)
Mutual labels:  nestjs, nestjs-mailer
Spamscope
Fast Advanced Spam Analysis Tool
Stars: ✭ 223 (+171.95%)
Mutual labels:  smtp, outlook
Free Email Forwarding
The best free email forwarding for custom domains. Visit our website to get started (SMTP server)
Stars: ✭ 2,024 (+2368.29%)
Mutual labels:  smtp, nodemailer
Maildev
📫 SMTP Server + Web Interface for viewing and testing emails during development.
Stars: ✭ 3,102 (+3682.93%)
Mutual labels:  smtp, nodemailer
layouts
Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.
Stars: ✭ 28 (-65.85%)
Mutual labels:  handlebars, ejs
node-backend-template
A template for NodeJS backend projects
Stars: ✭ 19 (-76.83%)
Mutual labels:  handlebars, nodemailer
Nest User Auth
A starter build for a back end which implements managing users with MongoDB, Mongoose, NestJS, Passport-JWT, and GraphQL.
Stars: ✭ 145 (+76.83%)
Mutual labels:  nodemailer, nestjs
Friend.ly
A social media platform with a friend recommendation engine based on personality trait extraction
Stars: ✭ 41 (-50%)
Mutual labels:  ejs, nodemailer
Webpack Seed
🚀 A Multi-Page Application base on webpack and babel. webpack搭建基于ES6,支持模板的多页面项目
Stars: ✭ 113 (+37.8%)
Mutual labels:  handlebars, ejs
node-emails-from-csv
A simple NodeJS aplication that helps sending emails for events. Uses CSV files for target users.
Stars: ✭ 18 (-78.05%)
Mutual labels:  handlebars, nodemailer

Nest Logo

Demo implementation on the mailer modules for Nest framework (node.js) using Nodemailer library

Nestjs-mailer starter kit / project for your NestJs project.

Goals

The main goal of this kit is to quickly get you started on your project with Nestjs Mailer, bringing a solid layout foundation to work upon.

Usage

Import the MailerModule into the root AppModule

Synchronous import

//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';  
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';

@Module({
  imports: [
    MailerModule.forRoot({
      transport: {
        host: 'smtp.example.com',
        port: 587,
        secure: false, // upgrade later with STARTTLS
        auth: {
          user: "username",
          pass: "password",
        },
      },
      defaults: {
        from:'"nest-modules" <[email protected]>',
      },
      template: {
        dir: process.cwd() + '/templates/',
        adapter: new HandlebarsAdapter(), // or new PugAdapter()
        options: {
          strict: true,
        },
      },
    }),
  ],
})
export class AppModule {}

Asynchronous import

//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';  
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';

@Module({
  imports: [
    MailerModule.forRootAsync({
      useFactory: () => ({
        transport: {
          host: 'smtp.example.com',
          port: 587,
          secure: false, // upgrade later with STARTTLS
          auth: {
            user: "username",
            pass: "password",
          },
        },
        defaults: {
          from:'"nest-modules" <[email protected]>',
        },
        template: {
          dir: process.cwd() + '/templates/',
          adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
          options: {
            strict: true,
          },
        },
      }),
    }),
  ],
})
export class AppModule {}
  • We have used Handlebars in above example, for EJS and Pug use below mentioned example of adapter import

Pug

//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';  
import { PugAdapter } from '@nestjs-modules/mailer/dist/adapters/pug.adapter';

EJS

//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';  
import { EjsAdapter } from '@nestjs-modules/mailer/dist/adapters/ejs.adapter';

After this, MailerService will be available to inject across entire project, for example in this way :

import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';

@Injectable()
export class ExampleService {
  constructor(private readonly mailerService: MailerService) {}
}

MailerProvider exports the sendMail() function to which you can pass the message options (sender, email subject, recipient, body content, etc)

sendMail() accepts the same fields as nodemailer email message

import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';

@Injectable()
export class ExampleService {
  constructor(private readonly mailerService: MailerService) {}
  
  public example(): void {
    this
      .mailerService
      .sendMail({
        to: '[email protected]', // list of receivers
        from: '[email protected]', // sender address
        subject: 'Testing Nest MailerModule ✔', // Subject line
        text: 'welcome', // plaintext body
        html: '<b>welcome</b>', // HTML body content
      })
      .then((success) => {
        console.log(success)
      })
      .catch((err) => {
        console.log(err)
      });
  }
  
  public example2(): void {
    this
      .mailerService
      .sendMail({
        to: '[email protected]',
        from: '[email protected]',
        subject: 'Testing Nest Mailermodule with template ✔',
        template: 'index', // The `.pug` or `.hbs` extension is appended automatically.
        context: {  // Data to be sent to template engine.
          code: 'cf1a3f828287',
          username: 'john doe',
        },
      })
       .then((success) => {
        console.log(success)
      })
      .catch((err) => {
        console.log(err)
      });
  }
  
  public example3(): void {
    this
      .mailerService
      .sendMail({
        to: '[email protected]',
        from: '[email protected]',
        subject: 'Testing Nest Mailermodule with template ✔',
        template: '/index', // The `.pug` or `.hbs` extension is appended automatically.
        context: {  // Data to be sent to template engine.
          code: 'cf1a3f828287',
          username: 'john doe',
        },
      })
      .then((success) => {
        console.log(success)
      })
      .catch((err) => {
        console.log(err)
      });
  }
}

Make a template named folder at the root level of the project and keep all the email-templates in the that folder with .hbs extension. This implementation uses handlebars as a view-engine and outlook as the smtp.

Configuration

Dotenv module has been used for sender's email and password keep. This kit is implemented with outlook smtp, while we can make changes in the app.module.ts configurations for other services. As the nestjs-mailer is built on top of nodemailer, the required configurations can be found here Nodemailer / smtp.

Special thanks to https://github.com/leemunroe/responsive-html-email-template for providing email-templates

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].