Nodemailer is a module for Node.js applications to allow easy as cake email sending. The project got started back in 2010 when there was no sane option to send email messages, today it is the solution most Node.js users turn to by default.
npm install nodemailer
npm install dotenv
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // Use `true` for port 465, `false` for all other ports
auth: {
user: "[email protected]",
pass: "jn7jnAPss4f63QBp6D",
},
});
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// send mail with defined transport object
const info = await transporter.sendMail({
from: '"Maddison Foo Koch 👻" <[email protected]>', // sender address
to: "[email protected], [email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});
console.log("Message sent: %s", info.messageId);
// Message sent: <[email protected]>
}
main().catch(console.error);
-
Visit https://myaccount.google.com/ then to Security then to 2fa, enable 2fa
-
Search for App passwords, the create one e.g Name: Nodemailer Jedybrown Ventures, password =
dwxm naum ylkg cfgd
-
Run
node sendMail.js
to send tthe mail to customers.