mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 13:37:09 -04:00
Fix SMTP port lost after upgrade. STMP settings are made only with environment variables on non-Sandstorm platforms.
Note: Sending email on Sandstorm Wekan does not work yet. Thanks to jrsupplee and xet7 ! Fixes #3529, Fixes #3016, Fixes #2375, Fixes #2598, Fixes wekan/wekan-snap#78
This commit is contained in:
parent
8f5089fd46
commit
65b8220fe5
2 changed files with 65 additions and 50 deletions
|
@ -80,39 +80,40 @@ template(name="general")
|
|||
|
||||
template(name='email')
|
||||
ul#email-setting.setting-detail
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-host'}}
|
||||
.description {{_ 'smtp-host-description'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-host(type="text", placeholder="smtp.domain.com" value="{{currentSetting.mailServer.host}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-port'}}
|
||||
.description {{_ 'smtp-port-description'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-port(type="text", placeholder="25" value="{{currentSetting.mailServer.port}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-username'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-username(type="text", placeholder="{{_ 'username'}}" value="{{currentSetting.mailServer.username}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-password'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-password(type="password", placeholder="{{_ 'password'}}" value="")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-tls'}}
|
||||
.form-group
|
||||
a.flex.js-toggle-tls
|
||||
.materialCheckBox#mail-server-tls(class="{{#if currentSetting.mailServer.enableTLS}}is-checked{{/if}}")
|
||||
if isSandstorm
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-host'}}
|
||||
.description {{_ 'smtp-host-description'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-host(type="text", placeholder="smtp.domain.com" value="{{currentSetting.mailServer.host}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-port'}}
|
||||
.description {{_ 'smtp-port-description'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-port(type="text", placeholder="25" value="{{currentSetting.mailServer.port}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-username'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-username(type="text", placeholder="{{_ 'username'}}" value="{{currentSetting.mailServer.username}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-password'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-password(type="password", placeholder="{{_ 'password'}}" value="")
|
||||
li.smtp-form
|
||||
.title {{_ 'smtp-tls'}}
|
||||
.form-group
|
||||
a.flex.js-toggle-tls
|
||||
.materialCheckBox#mail-server-tls(class="{{#if currentSetting.mailServer.enableTLS}}is-checked{{/if}}")
|
||||
|
||||
span {{_ 'smtp-tls-description'}}
|
||||
span {{_ 'smtp-tls-description'}}
|
||||
|
||||
li.smtp-form
|
||||
.title {{_ 'send-from'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-from(type="email", placeholder="no-reply@domain.com" value="{{currentSetting.mailServer.from}}")
|
||||
li.smtp-form
|
||||
.title {{_ 'send-from'}}
|
||||
.form-group
|
||||
input.wekan-form-control#mail-server-from(type="email", placeholder="no-reply@domain.com" value="{{currentSetting.mailServer.from}}")
|
||||
|
||||
li
|
||||
button.js-save.primary {{_ 'save'}}
|
||||
li
|
||||
button.js-save.primary {{_ 'save'}}
|
||||
|
||||
li
|
||||
button.js-send-smtp-test-email.primary {{_ 'send-smtp-test'}}
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
|
||||
// in the package definition.
|
||||
const isSandstorm =
|
||||
Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm;
|
||||
|
||||
Settings = new Mongo.Collection('settings');
|
||||
|
||||
Settings.attachSchema(
|
||||
|
@ -144,29 +149,38 @@ if (Meteor.isServer) {
|
|||
};
|
||||
Settings.insert(defaultSetting);
|
||||
}
|
||||
const newSetting = Settings.findOne();
|
||||
if (!process.env.MAIL_URL && newSetting.mailUrl())
|
||||
if (isSandstorm) {
|
||||
// At Sandstorm, Admin Panel has SMTP settings
|
||||
const newSetting = Settings.findOne();
|
||||
if (!process.env.MAIL_URL && newSetting.mailUrl())
|
||||
process.env.MAIL_URL = newSetting.mailUrl();
|
||||
Accounts.emailTemplates.from = process.env.MAIL_FROM
|
||||
? process.env.MAIL_FROM
|
||||
: newSetting.mailServer.from;
|
||||
});
|
||||
Settings.after.update((userId, doc, fieldNames) => {
|
||||
// assign new values to mail-from & MAIL_URL in environment
|
||||
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 = `${protocol}${doc.mailServer.host}:${doc.mailServer.port}/`;
|
||||
} else {
|
||||
process.env.MAIL_URL = `${protocol}${
|
||||
doc.mailServer.username
|
||||
}:${encodeURIComponent(doc.mailServer.password)}@${
|
||||
doc.mailServer.host
|
||||
}:${doc.mailServer.port}/`;
|
||||
}
|
||||
Accounts.emailTemplates.from = doc.mailServer.from;
|
||||
Accounts.emailTemplates.from = process.env.MAIL_FROM
|
||||
? process.env.MAIL_FROM
|
||||
: newSetting.mailServer.from;
|
||||
} else {
|
||||
// Not running on Sandstorm, so using environment variables
|
||||
Accounts.emailTemplates.from = process.env.MAIL_FROM;
|
||||
}
|
||||
});
|
||||
if (isSandstorm) {
|
||||
// At Sandstorm Wekan Admin Panel, save SMTP settings.
|
||||
Settings.after.update((userId, doc, fieldNames) => {
|
||||
// assign new values to mail-from & MAIL_URL in environment
|
||||
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 = `${protocol}${doc.mailServer.host}:${doc.mailServer.port}/`;
|
||||
} else {
|
||||
process.env.MAIL_URL = `${protocol}${
|
||||
doc.mailServer.username
|
||||
}:${encodeURIComponent(doc.mailServer.password)}@${
|
||||
doc.mailServer.host
|
||||
}:${doc.mailServer.port}/`;
|
||||
}
|
||||
Accounts.emailTemplates.from = doc.mailServer.from;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getRandomNum(min, max) {
|
||||
const range = max - min;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue