Created
February 8, 2012 00:45
-
-
Save wereHamster/1763610 to your computer and use it in GitHub Desktop.
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
var spawn = require('child_process').spawn; | |
exports.send = function(email, config, callback) { | |
var path = typeof config === "string" ? config : "sendmail"; | |
// Spawn sendmail. When it exits invoke the callback. | |
child = spawn(path, [ '-t' ]); | |
child.on('exit', function(code, signal) { | |
if (code !== 0) { | |
callback && callback(code, null); | |
} else { | |
callback && callback(null, true); | |
} | |
}); | |
// Prepare the data and feed it to sendmail. Omnomnom. | |
email.prepareVariables(); | |
child.stdin.write(email.generateHeaders()); | |
child.stdin.write("\r\n\r\n"); | |
child.stdin.write(email.generateBody()); | |
child.stdin.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment