Created
July 8, 2015 15:32
-
-
Save rahul-desai3/28073c18a5a70379ac76 to your computer and use it in GitHub Desktop.
Unable to send emails to Haraka email server
This file contains hidden or 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
//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', | |
auth: { | |
user: '[email protected]', | |
pass: '' | |
} | |
}); | |
// 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 <[email protected]>', // sender address | |
to: '[email protected]', // 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.log(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