Hello Everyone
In this post, we will learn how to send Emails to any Email address using node.js. By following the steps at the end of this tutorial you will able to send any message through Email address. We are going to use Gmail to send Emails to other Gmail addresses. So without wasting time le's begin.
npm install node-mailer.Now copy-paste the whole code.
const nodemailer = require('nodemailer');
const config = require('./config.json');
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: config.from,
pass: config.pass
}
});
let mailOptions = {
from: config.from,
to: config.to,
subject: 'Hive Post',
text: 'This is mail sent by Noed-Mailer '
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent to the given adress');
}
});
Create a new file name it index.js and paste the whole code int it.
create another file and name it confog.json.
{
"from": "YOUR-GMAIL",
"to": "WHERE-YOU-WANT-SEND",
"pass": "YOUR-PASSWORD"
}
copy the above code into it and change its values.