2015-07-23 19:02:16 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var assert = require('assert'),
|
|
|
|
debug = require('debug')('e2e:mailer'),
|
2015-07-24 02:10:04 +00:00
|
|
|
postmark = require('postmark')(process.env.POSTMARK_API_KEY_TOOLS),
|
2015-07-23 19:02:16 +00:00
|
|
|
util = require('util');
|
|
|
|
|
|
|
|
exports = module.exports = {
|
|
|
|
sendEndToEndTestResult: sendEndToEndTestResult
|
|
|
|
};
|
|
|
|
|
|
|
|
function send(options, callback) {
|
|
|
|
assert.strictEqual(typeof options, 'object');
|
|
|
|
assert.strictEqual(typeof options.to, 'string');
|
|
|
|
assert.strictEqual(typeof options.subject, 'string');
|
|
|
|
assert.strictEqual(typeof options.text, 'string');
|
|
|
|
|
|
|
|
debug('Sending email to %s with subject "%s".', options.to, options.subject);
|
|
|
|
|
|
|
|
postmark.send({
|
|
|
|
'From': options.from || 'no-reply@cloudron.io',
|
|
|
|
'To': options.to,
|
|
|
|
'Bcc': options.bcc,
|
|
|
|
'Subject': options.subject,
|
|
|
|
'TextBody': options.text,
|
|
|
|
'HtmlBody': options.html,
|
|
|
|
'Tag': 'Important'
|
|
|
|
}, function (error, success) {
|
|
|
|
if (error) {
|
|
|
|
console.error('Unable to send via postmark: ', error);
|
|
|
|
return callback(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendEndToEndTestResult(topic, stdout, stderr, callback) {
|
|
|
|
debug('Sending e2e test result for %s', topic);
|
|
|
|
|
|
|
|
var mailOptions = {
|
|
|
|
to: 'admin@cloudron.io',
|
|
|
|
subject: util.format('E2E test results for box %s', topic),
|
|
|
|
text: 'stdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n'
|
|
|
|
};
|
|
|
|
|
|
|
|
send(mailOptions, callback);
|
|
|
|
}
|