Created
February 17, 2014 14:03
-
-
Save choonkeat/9051121 to your computer and use it in GitHub Desktop.
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
var http = require('http'); | |
var querystring = require('querystring'); | |
var MailParser = require("mailparser").MailParser; // https://github.com/andris9/mailparser | |
var server = http.createServer(); | |
server.addListener('request', function(req, res) { | |
var chunks = []; | |
req.on('data', chunks.push.bind(chunks)); | |
req.on('end', function() { | |
var mailparser = new MailParser(); | |
mailparser.on("end", function(mail_object) { | |
// API for https://github.com/andris9/mailparser | |
mail_object.from; // [ { address: '[email protected]', name: 'Sender Name' } ] | |
mail_object.to; // [ { address: '[email protected]', name: '' } ] | |
mail_object.subject; // "Testing 1 2 3" | |
mail_object.html; | |
mail_object.text; | |
console.log(mail_object.from, mail_object.to, mail_object.subject); | |
console.log(mail_object); | |
res.writeHead(200, {'content-type': 'text/plain'}); | |
res.end(); | |
}); | |
var params = querystring.parse(chunks.join("").toString()); | |
mailparser.write(params['message']); | |
mailparser.end(); | |
}); | |
}); | |
var port = process.env.PORT || 3000; | |
console.log(' [*] Listening on 0.0.0.0:' + port); | |
server.listen(port, '0.0.0.0'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great 👍