Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Nest Mailman | 194 | 1 | 3 months ago | 18 | August 26, 2021 | 1 | mit | TypeScript | ||
📮 The mailer package for your NestJS Applications. | ||||||||||
Bulk Mail Cli | 108 | 2 | 4 years ago | 33 | March 01, 2020 | n,ull | gpl-3.0 | TypeScript | ||
Do quick, hassle-free email marketing with this small but very powerful tool! 🔥 | ||||||||||
Mailman | 91 | 4 | 3 | 8 years ago | 11 | June 24, 2015 | 1 | JavaScript | ||
Send emails in a comfortable way via models. | ||||||||||
84 | 110 | 8 | 2 months ago | 45 | May 18, 2022 | mit | TypeScript | |||
AdonisJS Email Provider | ||||||||||
Feathers Mailer | 82 | 26 | 13 | 4 months ago | 10 | August 03, 2021 | mit | TypeScript | ||
Feathers mailer service using nodemailer | ||||||||||
Nestjs Mailer | 63 | 2 years ago | 2 | mit | Handlebars | |||||
🌈 A simple implementation example with and without email-templates using mailer module for nest js built on top of nodemailer. | ||||||||||
Sails Service Mailer | 29 | 50 | 2 | 3 years ago | 13 | January 27, 2016 | mit | JavaScript | ||
Service for Sails framework with Mailer features [DEAD] | ||||||||||
Aws Lambda Node Mailer | 24 | 7 years ago | mit | HTML | ||||||
NodeJs code for Firing Email via AWS-Lambda and SES | ||||||||||
Egg Mailer | 21 | 1 | 2 years ago | 8 | May 28, 2021 | 2 | mit | JavaScript | ||
🥚 mailer plugin for egg | ||||||||||
Express Smtp Mailer | 20 | 2 years ago | 2 | November 02, 2020 | 6 | mit | JavaScript | |||
A production-ready Node backend with an Express SMTP mail server configurable for use with contact forms, subscriptions, etc. |
Demo implementation on the mailer modules for Nest framework (node.js) using Nodemailer library
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.
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 {}
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.
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 leemunroe/responsive-html-email-template for providing email-templates