diff --git a/src/mail_templates/box_update_available.ejs b/src/mail_templates/box_update_available.ejs new file mode 100644 index 000000000..16161f6ac --- /dev/null +++ b/src/mail_templates/box_update_available.ejs @@ -0,0 +1,55 @@ +<%if (format === 'text') { %> + +Dear <%= cloudronName %> Admin, + +Version <%= newBoxVersion %> for Cloudron <%= fqdn %> is now available! + +Your Cloudron will update automatically tonight. Alternately, update immediately at <%= webadminUrl %>. + +Changelog: +<% for (var i = 0; i < changelog.length; i++) { %> + * <%- changelog[i] %> +<% } %> + +Thank you, +your Cloudron + +<% } else { %> + +
+ + + +

Dear <%= cloudronName %> Admin,

+ +
+

+ Version <%= newBoxVersion %> for Cloudron <%= fqdn %> is now available! +

+ +

+ Your Cloudron will update automatically tonight.
+ Alternately, update immediately here. +

+ +
Changelog:
+ + +
+
+
+ +
+ Powered by Cloudron. +
+ +
+ + + +<% } %> + diff --git a/src/mailer.js b/src/mailer.js index fce6a8ea9..89d35dcb8 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -8,6 +8,7 @@ exports = module.exports = { userRemoved: userRemoved, adminChanged: adminChanged, passwordReset: passwordReset, + boxUpdateAvailable: boxUpdateAvailable, appUpdateAvailable: appUpdateAvailable, sendInvite: sendInvite, @@ -402,6 +403,50 @@ function appDied(app) { }); } +function boxUpdateAvailable(newBoxVersion, changelog) { + assert.strictEqual(typeof newBoxVersion, 'string'); + assert(util.isArray(changelog)); + + getAdminEmails(function (error, adminEmails) { + if (error) return console.log('Error getting admins', error); + + settings.getCloudronName(function (error, cloudronName) { + if (error) { + console.error(error); + cloudronName = 'Cloudron'; + } + + var converter = new showdown.Converter(); + + var templateData = { + fqdn: config.fqdn(), + webadminUrl: config.adminOrigin(), + newBoxVersion: newBoxVersion, + changelog: changelog, + changelogHTML: changelog.map(function (e) { return converter.makeHtml(e); }), + cloudronName: cloudronName, + cloudronAvatarUrl: config.adminOrigin() + '/api/v1/cloudron/avatar' + }; + + var templateDataText = JSON.parse(JSON.stringify(templateData)); + templateDataText.format = 'text'; + + var templateDataHTML = JSON.parse(JSON.stringify(templateData)); + templateDataHTML.format = 'html'; + + var mailOptions = { + from: mailConfig().from, + to: adminEmails.join(', '), + subject: util.format('%s has a new update available', config.fqdn()), + text: render('box_update_available.ejs', templateDataText), + html: render('box_update_available.ejs', templateDataHTML) + }; + + enqueue(mailOptions); + }); + }); +} + function appUpdateAvailable(app, updateInfo) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof updateInfo, 'object');