DEV Community

loading...

NodeJS – Send email by Nodemailer

loizenai
Software Engineer - Founder at https://loizenai.com
・1 min read

https://grokonez.com/node-js/nodejs-send-email-by-nodemailer-example

NodeJS – Send email by Nodemailer

In the tutorial, we show you how to send email from Node.js applications by Nodemailer module.

Nodemailer Module

Nodemailer is licensed under MIT license. It provides an easy way to send email.

To download and install it, we use below commandline:


$npm install nodemailer --save

Nodemailer Send Mail


var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  // example with google mail service
  host: 'smtp.gmail.com',
  port: 587,
  secure: false, // true for 465, false for other ports
  auth: {
    user: 'send-email@gmail.com', // replace by your email to practice
    pass: '*****' // replace by your-password
  }
});

var mailOptions = {
  from: 'send-mail@gmail.com',
  to: 'to-email-1@gmail.com, to-email-2@gmail.com',
  subject: 'Sending Email using Nodemailer',
  
  /*
     for plain text body
     -> text: 'Just Testing!'
  */
  
  // html body
  html: '

Hello world!

The mail has been sent from Node.js application!

' }; transporter.sendMail(mailOptions, (error, info) => { if (error) return console.log(error); console.log('Email sent: ' + info.response); });

More at:

https://grokonez.com/node-js/nodejs-send-email-by-nodemailer-example

NodeJS – Send email by Nodemailer

Discussion (1)

Collapse
konferbe profile image
Steve Lebleu

Thanks for sharing ! Here a package which can help with email sending in node.js environment. One library for many providers.

GitHub logo konfer-be / cliam

Agnostic transactional email sending in Node.js environment

Cliam

Build Status Coverage Status CodeFactor Grade Requires.io (branch) GPL Licence

Transactional emails with a kick

Agnostic transactional email sending in Node.js environment 💥 💪 💊

> Why ?

To improve and facilitate the implementation, flexibility and maintenance of transactional emailing tasks.

> Features

  • Agnostic transactional email sending using web API or SMTP server. One input, one output.
  • Configuration based, not implementation based : easy switch between different modes.
  • Normalized transactions events.
  • Securized payloads.
  • Customisable default templates.

> Table of contents

> Requirements

  • Node.js >= 14.16.0
  • NPM >= 6.14.11

> Getting started

Install

> npm i cliam --save
Enter fullscreen mode Exit fullscreen mode

Configure

Create a .cliamrc.json file on the root of your project.

> touch .cliamrc.json
Enter fullscreen mode Exit fullscreen mode

Define a minimalist configuration in .cliamrc.json newly created:

{
  "consumer": {
    "domain": "https://www.john-doe.com"
  }
  "mode": {
    "api": {
      "name"
Enter fullscreen mode Exit fullscreen mode