Skip to content

Instantly share code, notes, and snippets.

@LooseTerrifyingSpaceMonkey
Created June 29, 2022 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LooseTerrifyingSpaceMonkey/c1cdb87e41b097bde328644697adcc14 to your computer and use it in GitHub Desktop.
Save LooseTerrifyingSpaceMonkey/c1cdb87e41b097bde328644697adcc14 to your computer and use it in GitHub Desktop.
Example of sending emails in Node.js with Nodemailer
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'yourgmail@gmail.com',
pass: 'yourapplicationpassword'
}
});
/*const transporter_smtp = nodemailer.createTransport({
host: 'smtp.mailserver.com',
port: 2525,
auth: {
user: 'youremail@mailserver.com',
pass: 'yoursecurepassword'
}
});*/
const email = {
from: 'yourgmail@gmail.com',
to: 'yourfriend@yahoo.com',
subject: 'Sending A Simple Email using Node.js',
text: 'Now is the time for all good men to send Email via Node.js!'
};
transporter.verify(function (error, success) {
if(error) {
console.log(error);
} else {
console.log('Server validation done and ready for messages.')
}
});
transporter.sendMail(email, function(error, success){
if (error) {
console.log(error);
} else {
console.log('NodeMailer Email sent: ' + success.response);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment