Skip to content

Instantly share code, notes, and snippets.

@wereHamster
Created February 8, 2012 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wereHamster/1763610 to your computer and use it in GitHub Desktop.
Save wereHamster/1763610 to your computer and use it in GitHub Desktop.
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