mirror of
https://github.com/plankanban/planka.git
synced 2025-12-20 17:25:39 +03:00
feat: Add ability to configure and test SMTP via UI
This commit is contained in:
61
server/api/helpers/utils/make-smtp-transporter.js
Normal file
61
server/api/helpers/utils/make-smtp-transporter.js
Normal file
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
defaultOptions: {
|
||||
type: 'json',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let config;
|
||||
let sourceConfig;
|
||||
|
||||
if (sails.config.custom.smtpHost) {
|
||||
sourceConfig = sails.config.custom;
|
||||
} else {
|
||||
config = await Config.qm.getOneMain();
|
||||
|
||||
if (config.smtpHost) {
|
||||
sourceConfig = config;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sourceConfig) {
|
||||
return {
|
||||
config,
|
||||
transporter: null,
|
||||
};
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(
|
||||
{
|
||||
...inputs.defaultOptions,
|
||||
host: sourceConfig.smtpHost,
|
||||
port: sourceConfig.smtpPort,
|
||||
name: sourceConfig.smtpName,
|
||||
secure: sourceConfig.smtpSecure,
|
||||
auth: sourceConfig.smtpUser && {
|
||||
user: sourceConfig.smtpUser,
|
||||
pass: sourceConfig.smtpPassword,
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: sourceConfig.smtpTlsRejectUnauthorized,
|
||||
},
|
||||
},
|
||||
{
|
||||
from: sourceConfig.smtpFrom,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
transporter,
|
||||
config,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user