Node.js is a powerful tool for automating email sending. With a few simple lines of code, you can set up a node script to send an email automatically.
To start, you will need to create a file called "sendEmail.js" and include the following code:
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'yourEmail@gmail.com',
pass: 'yourPassword'
}
});
var mailOptions = {
from: 'yourEmail@gmail.com',
to: 'receiverEmail@gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Top comments (0)