Want to send email using node.js ??,
Its simple here are some steps that will allow you to send email using node.js using nodemailer.
STEP 1 - Install nodemailer
Use following command to install nodemailer
npm install nodemailer
STEP 2 - Create Transporter
import nodemailer and create transporter
var nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
service: 'gmail' // here I am using gmail service
auth:{
user: 'emailid@gmail.com,
passoword: 'your gmail app passsword'
}
});
Remember the password you are going to use is not the password for email rather you will have to generate application password provided by gmail. Click here to see how to generate application password
STEP 3 - Create Options
let mailOptions = {
to: 'myfriend@yahoo.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
STEP 4 - Send Email
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
IF YOU LIKED THIS ARTICLE MAKE SURE TO FOLLOW ME ON DEV.TO AND ON INSTAGRAM
Top comments (2)
Thanks for sharing ! Here a package which can help with email sending in node.js environment. One library for many providers.
konfer-be / cliam
Agnostic transactional email sending in Node.js environment
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
> Table of contents
> Requirements
> Getting started
Install
> npm i cliam --save
Configure
Create a .cliamrc.json file on the root of your project.
> touch .cliamrc.json
Define a minimalist configuration in .cliamrc.json newly created:
Thanks for sharing