Skip to content

Instantly share code, notes, and snippets.

@clux
Last active December 26, 2015 06:19
Show Gist options
  • Save clux/7107447 to your computer and use it in GitHub Desktop.
Save clux/7107447 to your computer and use it in GitHub Desktop.
Forward posts to email
// Create a SMTP transport object
var nodemailer = require('nodemailer');
var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
user: "clux.nodemailer@gmail.com",
pass: "mailpass"
}
});
var mailStr = function (str) {
var message = {
from: 'AppName <clux.nodemailer@gmail.com>',
to: '"Destination Dewd" <analsandblaster@gmail.com>',
subject: 'New submission',
text: str,
};
console.log('sending', message); // commented out next line when dev testing and just watch for this
transport.sendMail(message, function (err) { console.log(err ? err.message : 'Mail sent')});
});
var http = require('http');
http.createServer(function (req, res) {
var body = '';
req.on('data', function(chunk) {
body += chunk.toString();
});
req.on('end', function() {
mailStr(body);
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.end();
});
}).listen(8000);
@clux
Copy link
Author

clux commented Oct 22, 2013

let the HTML form post to localhost:8000 while having this file running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment