Skip to content

Instantly share code, notes, and snippets.

@Vinay08sharma
Created February 19, 2022 20:04
Show Gist options
  • Save Vinay08sharma/68693bb820bb27c2f548c9d6e93604f7 to your computer and use it in GitHub Desktop.
Save Vinay08sharma/68693bb820bb27c2f548c9d6e93604f7 to your computer and use it in GitHub Desktop.
Email Util through which email can be sent via code in JS using nodemailer
const nodemailer = require("nodemailer");
function sendMail() {
let transporter = nodemailer.createTransport({
service:"gmail",
host: "smtp.gmail.com",
auth: {
user: "<senderUserName>", // add username
pass: "<senderPassword>", // password
}
})
let mailOptions = {
from: "sender@gmail.com",
to: "receiver@gmail.com",
subject: "Hello mail testing",
text: "Sending mail via nodemailer"
}
transporter.sendMail(mailOptions,(error,info) => {
if(error) {
console.log(error)
} else {
console.log(`Email sent : ${info.response}`);
}
})
} sendMail();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment