Skip to content

Instantly share code, notes, and snippets.

@rahul-desai3
Created July 9, 2015 14:22
Show Gist options
  • Save rahul-desai3/318ff2dfd31f463536bd to your computer and use it in GitHub Desktop.
Save rahul-desai3/318ff2dfd31f463536bd to your computer and use it in GitHub Desktop.
Unable to send emails to Gmail
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=1030;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('Welcome to Node.js localhost!\nPath Hit: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", PORT);
});
var nodemailer = require('nodemailer');
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'localhost'
});
// NB! No need to recreate the transporter object. You can use
// the same transporter object for all e-mails
// setup e-mail data with unicode symbols
var mailOptions = {
from: 'Peter Parkins <peter@vmail.com>', // sender address
to: 'rahuldesai209@gmail.com', // list of receivers
subject: 'Meeting', // Subject line
// text: 'How is it going?', // plaintext body
html: '<div>Hi Rahul,<br/>Can we meet after lunch today?<br/>Best,<br/>Peter Parkins</div>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.error(error);
}
console.log('Message sent: ' + info.response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment