diff options
author | Julen Landa Alustiza <julen@zokormazo.info> | 2017-03-30 19:13:57 +0200 |
---|---|---|
committer | Julen Landa Alustiza <julen@zokormazo.info> | 2017-03-30 19:13:57 +0200 |
commit | db2c381c005269557018b560a04abd0f59dfc7aa (patch) | |
tree | 41d3c77e351c463bf7c189358dde19e871dc4c5c /models/settings.js | |
parent | ee6aa7a6b20a3839f92d91e9bc24136aa07306b9 (diff) | |
download | wekan-db2c381c005269557018b560a04abd0f59dfc7aa.tar.gz wekan-db2c381c005269557018b560a04abd0f59dfc7aa.tar.bz2 wekan-db2c381c005269557018b560a04abd0f59dfc7aa.zip |
Add TLS toggle option to smtp configuration
Diffstat (limited to 'models/settings.js')
-rw-r--r-- | models/settings.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/models/settings.js b/models/settings.js index 0c2da4d3..e5b9783a 100644 --- a/models/settings.js +++ b/models/settings.js @@ -20,6 +20,10 @@ Settings.attachSchema(new SimpleSchema({ type: String, optional: true, }, + 'mailServer.enableTLS': { + type: Boolean, + optional: true, + }, 'mailServer.from': { type: String, optional: true, @@ -38,10 +42,11 @@ Settings.helpers({ if (!this.mailServer.host) { return null; } + const protocol = this.mailServer.enableTLS ? 'smtps://' : 'smtp://'; if (!this.mailServer.username && !this.mailServer.password) { - return `smtp://${this.mailServer.host}:${this.mailServer.port}/`; + return `${protocol}${this.mailServer.host}:${this.mailServer.port}/`; } - return `smtp://${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`; + return `${protocol}${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`; }, }); Settings.allow({ @@ -62,7 +67,7 @@ if (Meteor.isServer) { if(!setting){ const now = new Date(); const defaultSetting = {disableRegistration: false, mailServer: { - username: '', password:'', host: '', port:'', from: '', + username: '', password: '', host: '', port: '', enableTLS: false, from: '', }, createdAt: now, modifiedAt: now}; Settings.insert(defaultSetting); } @@ -72,11 +77,12 @@ if (Meteor.isServer) { }); Settings.after.update((userId, doc, fieldNames) => { // assign new values to mail-from & MAIL_URL in environment - if (_.contains(fieldNames, 'mailServer') && _.contains(fieldNames, 'host')) { + if (_.contains(fieldNames, 'mailServer') && doc.mailServer.host) { + const protocol = doc.mailServer.enableTLS ? 'smtps://' : 'smtp://'; if (!doc.mailServer.username && !doc.mailServer.password) { - process.env.MAIL_URL = `smtp://${doc.mailServer.host}:${doc.mailServer.port}/`; + process.env.MAIL_URL = `${protocol}${doc.mailServer.host}:${doc.mailServer.port}/`; } else { - process.env.MAIL_URL = `smtp://${doc.mailServer.username}:${doc.mailServer.password}@${doc.mailServer.host}:${doc.mailServer.port}/`; + process.env.MAIL_URL = `${protocol}${doc.mailServer.username}:${doc.mailServer.password}@${doc.mailServer.host}:${doc.mailServer.port}/`; } Accounts.emailTemplates.from = doc.mailServer.from; } |