Last active
December 26, 2015 06:19
-
-
Save clux/7107447 to your computer and use it in GitHub Desktop.
Forward posts to email
This file contains 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
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let the HTML form post to localhost:8000 while having this file running