Skip to content

Instantly share code, notes, and snippets.

@jafstar
Created December 19, 2011 05:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jafstar/1495479 to your computer and use it in GitHub Desktop.
Save jafstar/1495479 to your computer and use it in GitHub Desktop.
Formidable + CloudMailin
//MSG
app.post('/msg', function(req, res){
if (req.url == '/msg') {
var form = new formidable.IncomingForm(),
fields = [];
form.on('error', function(err) {
res.writeHead(200, {'content-type': 'text/plain'});
res.end('error:\n\n'+util.inspect(err));
}).on('field', function(field, value) {
fields.push([field, value]);
}).on('end', function() {
console.log('-> post done');
res.writeHead(200, {'content-type': 'text/plain'});
res.end('received fields:\n\n '+ util.inspect(fields));
//FROM
console.log(fields[2][1]);
//PLAIN
console.log(fields[5][1]);
//HTML
console.log(fields[6][1]);
});
form.parse(req);
} else {
res.writeHead(404, {'content-type': 'text/plain'});
res.end('404');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment