Example of sending emails in Node.js with 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') | |
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