Created
February 19, 2022 20:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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