mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02: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
|
@ -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