/* jslint node: true */ 'use strict'; var assert = require('assert'), debug = require('debug')('e2e:mailer'), postmark = require('postmark')(process.env.POSTMARK_API_KEY_TOOLS), util = require('util'); exports = module.exports = { sendMailToCloudronUser: sendMailToCloudronUser, 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, versionInfo, stdout, stderr, callback) { debug('Sending e2e test result for %s', topic); var mailOptions = { to: 'test@cloudron.io', subject: util.format('E2E test results for %s', topic), text: versionInfo + '\n\nstdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n' }; send(mailOptions, callback); } function sendMailToCloudronUser(email, callback) { debug('Sending test mail to %s', email); var mailOptions = { to: email, subject: 'Hi from e2e test', text: 'I hope you get this. The release depends on you!' }; send(mailOptions, callback); }