NodeJS | Send email including from, to, cc and bcc fields using nodemailer in just 3 steps

Опубликовано: 30 Ноябрь 2019
на канале: Technical Babaji (Tarique Akhtar)
4,979
60

Sending an email in nodejs is a breeze thanks to NodeMailer. Let me walk you through the process of sending an email using NodeMailer.
firstly install nodemailer in your node application.



npm install --save nodemailer



after installing the nodemailer, in your main node.js file require the nodemailer
var nodemailer = require('nodemailer');
nodemailer needs a transport service using which it can send emails. In this example I am using gmail.

inside your app.js file write
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'yourpassword'
}
})
We used gmail as our transport service.
The next up is our auth object in which we have to specify our email address and password of gmail for allowing nodemailer to login and send email using our gmail account.
Now we need a second configuration object where we will be configuring our email details.


const mailOptions = {
from: '[email protected]', // sender address
to: '[email protected]', // list of receivers
subject: 'Subject of your email', // Subject line
html: 'Your html here'// plain text body
};

Most important four options are :-

from : The sender of the email

to : The recipient of the email

subject : the subject of the email

html : all the magic happens here

Before sending your email using gmail you have to allow non secure apps to access gmail you can do this by going to your gmail settings here.


Смотрите видео NodeJS | Send email including from, to, cc and bcc fields using nodemailer in just 3 steps онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Technical Babaji (Tarique Akhtar) 30 Ноябрь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 4,979 раз и оно понравилось 60 людям.