Skip to content

Instantly share code, notes, and snippets.

@rahul-desai3
Last active August 29, 2015 14:24
Show Gist options
  • Save rahul-desai3/dcef485faeb8323e3e22 to your computer and use it in GitHub Desktop.
Save rahul-desai3/dcef485faeb8323e3e22 to your computer and use it in GitHub Desktop.
Unable to send emails to Gmail account
//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();
// 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: 'Rahul Desai <someUser@someDomain.com>', // sender address
to: 'myValidEmail@gmail.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔'
// , // plaintext body
// html: '<b>Hello world ✔</b>' // 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