Skip to content

Instantly share code, notes, and snippets.

@arkumish
Created December 5, 2019 13:13
Show Gist options
  • Save arkumish/d0e31b6dca3f33eaa2ba0135eba409bb to your computer and use it in GitHub Desktop.
Save arkumish/d0e31b6dca3f33eaa2ba0135eba409bb to your computer and use it in GitHub Desktop.
Send mail through Nodemail in NodeJS
const nodemailer = require("nodemailer"); //install this by "npm install nodemailer"
// Step 1
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'your email id', // your gmail account
pass: 'password' // your gmail password
}
});
// Step 2
let mailOptions = {
from: 'your email-id', // email sender
to: 'sender emailid', // email receiver
subject: 'your email subject',
text: 'mail text'
};
// Step 3
transporter.sendMail(mailOptions, (err, data) => {
if (err) {
return console.log('Error occurs');
}
return console.log('Email sent!!!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment