Use mail command instead of sendmail.

This commit is contained in:
Ian Webster
2015-11-06 00:24:25 -08:00
parent e1219bf32b
commit 2c2888fbe9
2 changed files with 49 additions and 33 deletions

View File

@@ -2,8 +2,11 @@ var providers = require('./providers.js')
, _ = require('underscore')
, exec = require('child_process').exec
, spawn = require('child_process').spawn;
var StringDecoder = require('string_decoder').StringDecoder;
var debugEnabled = false;
// NOTE: Change this if you are self-hosting!
var fromAddress = 'foo@bar.com';
//----------------------------------------------------------------
@@ -56,18 +59,22 @@ function sendText(phone, message, region, cb) {
_.each(providers_list, function(provider) {
var email = provider.replace('%s', phone);
email = 'Subject: Text\r\n\r\n' + email;
var child = spawn('sendmail', ['-f', fromAddress, email]);
child.stdout.on('data', output);
child.stderr.on('data', output);
var child = spawn('mail', ['-s', 'txt', '-a', 'From:' + fromAddress, email]);
var decoder = new StringDecoder('utf8');
child.stdout.on('data', function(data) {
output(decoder.write(data));
});
child.stderr.on('data', function(data) {
output(decoder.write(data));
});
child.on('error', function(data) {
output('sendmail failed', {email: email, data: data});
output('sendmail failed', {email: email, data: decoder.write(data)});
done();
});
child.on('exit', function(code, signal) {
done();
});
child.stdin.write(message + '\n.');
child.stdin.write(message + '\n');
child.stdin.end();
});
}