Skip to content

Instantly share code, notes, and snippets.

@iamabs2001
Created October 28, 2020 03:27
Show Gist options
  • Save iamabs2001/a9913b49b6f37132e8f35a2794bf8562 to your computer and use it in GitHub Desktop.
Save iamabs2001/a9913b49b6f37132e8f35a2794bf8562 to your computer and use it in GitHub Desktop.
Node.js send mail
var http = require('http');
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
}
});
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
text: 'my message body ? '
};
var server = http.createServer(function(requ, resp) {
if(requ.url=="/") {
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
resp.write("Mail has been sent :)");
}
});
}
});
server.listen(8080);
console.log("Server running at : 8080");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment