DEV Community

Ankan Saha
Ankan Saha

Posted on

2

Automate send email using nodejs

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)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay