Created
October 28, 2020 03:27
-
-
Save iamabs2001/a9913b49b6f37132e8f35a2794bf8562 to your computer and use it in GitHub Desktop.
Node.js send mail
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
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