make OTP plugin inherit SMTP relay configuration
Use rms.auth.smtp_relay settings as the primary source for OTP mail transport (host/port/auth/tls/from/replyTo), with existing OTP/env values only as fallback. This lets OTP delivery work immediately when relay settings are already configured.
This commit is contained in:
@@ -10,19 +10,43 @@ async function createPlugin(ctx) {
|
|||||||
let transportKey = "";
|
let transportKey = "";
|
||||||
|
|
||||||
function readTransportConfig() {
|
function readTransportConfig() {
|
||||||
const host = String(ctx.getSetting("host", ctx.env.SMTP_HOST || "")).trim();
|
const relaySetting = typeof ctx.getPluginSetting === "function"
|
||||||
const portRaw = Number(ctx.getSetting("port", ctx.env.SMTP_PORT || 587));
|
? (key, fallback = null) => ctx.getPluginSetting("rms.auth.smtp_relay", key, fallback)
|
||||||
const secure = String(ctx.getSetting("secure", ctx.env.SMTP_SECURE || "false")) === "true";
|
: (_key, fallback = null) => fallback;
|
||||||
const authUser = String(ctx.getSetting("authUser", ctx.env.SMTP_USER || "")).trim();
|
|
||||||
const authPass = String(ctx.getSetting("authPass", ctx.env.SMTP_PASS || "")).trim();
|
const host = String(
|
||||||
const allowInvalidCert = String(ctx.getSetting("allowInvalidCert", ctx.env.SMTP_ALLOW_INVALID_CERT || "false")) === "true";
|
relaySetting("host", ctx.getSetting("host", ctx.env.SMTP_HOST || ""))
|
||||||
|
).trim();
|
||||||
|
const portRaw = Number(
|
||||||
|
relaySetting("port", ctx.getSetting("port", ctx.env.SMTP_PORT || 587))
|
||||||
|
);
|
||||||
|
const secure = String(
|
||||||
|
relaySetting("secure", ctx.getSetting("secure", ctx.env.SMTP_SECURE || "false"))
|
||||||
|
) === "true";
|
||||||
|
const authUser = String(
|
||||||
|
relaySetting("authUser", ctx.getSetting("authUser", ctx.env.SMTP_USER || ""))
|
||||||
|
).trim();
|
||||||
|
const authPass = String(
|
||||||
|
relaySetting("authPass", ctx.getSetting("authPass", ctx.env.SMTP_PASS || ""))
|
||||||
|
).trim();
|
||||||
|
const allowInvalidCert = String(
|
||||||
|
relaySetting("allowInvalidCert", ctx.getSetting("allowInvalidCert", ctx.env.SMTP_ALLOW_INVALID_CERT || "false"))
|
||||||
|
) === "true";
|
||||||
|
const from = String(
|
||||||
|
relaySetting("from", ctx.getSetting("from", ctx.env.SMTP_FROM || "noreply@arcg.at"))
|
||||||
|
).trim() || "noreply@arcg.at";
|
||||||
|
const replyTo = String(
|
||||||
|
relaySetting("replyTo", ctx.getSetting("replyTo", ctx.env.SMTP_REPLY_TO || ""))
|
||||||
|
).trim();
|
||||||
return {
|
return {
|
||||||
host,
|
host,
|
||||||
port: Number.isFinite(portRaw) && portRaw > 0 ? portRaw : 587,
|
port: Number.isFinite(portRaw) && portRaw > 0 ? portRaw : 587,
|
||||||
secure,
|
secure,
|
||||||
authUser,
|
authUser,
|
||||||
authPass,
|
authPass,
|
||||||
allowInvalidCert
|
allowInvalidCert,
|
||||||
|
from,
|
||||||
|
replyTo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,12 +88,13 @@ async function createPlugin(ctx) {
|
|||||||
if (!recipient) {
|
if (!recipient) {
|
||||||
throw new Error("recipient missing");
|
throw new Error("recipient missing");
|
||||||
}
|
}
|
||||||
|
const transportConfig = readTransportConfig();
|
||||||
const entry = {
|
const entry = {
|
||||||
at: new Date().toISOString(),
|
at: new Date().toISOString(),
|
||||||
via: "rms.auth.otp_email",
|
via: "rms.auth.otp_email",
|
||||||
to: recipient,
|
to: recipient,
|
||||||
from: String(ctx.getSetting("from", ctx.env.SMTP_FROM || "noreply@arcg.at")),
|
from: transportConfig.from,
|
||||||
replyTo: String(ctx.getSetting("replyTo", ctx.env.SMTP_REPLY_TO || "")),
|
replyTo: transportConfig.replyTo,
|
||||||
subject: String(payload.subject || "ARCG OTP"),
|
subject: String(payload.subject || "ARCG OTP"),
|
||||||
text: String(payload.text || ""),
|
text: String(payload.text || ""),
|
||||||
html: String(payload.html || "")
|
html: String(payload.html || "")
|
||||||
|
|||||||
@@ -6703,6 +6703,7 @@ async function loadPlugins() {
|
|||||||
execMode: config.execMode,
|
execMode: config.execMode,
|
||||||
simulateHardware: config.simulateHardware,
|
simulateHardware: config.simulateHardware,
|
||||||
getSetting: (key, fallback = null) => getPluginSetting(manifest.id, key, fallback),
|
getSetting: (key, fallback = null) => getPluginSetting(manifest.id, key, fallback),
|
||||||
|
getPluginSetting: (pluginId, key, fallback = null) => getPluginSetting(pluginId, key, fallback),
|
||||||
commandRunner: runCommand,
|
commandRunner: runCommand,
|
||||||
executeCapability: async (capability, action, input = {}, meta = {}) => executeCapability(capability, action, input, meta),
|
executeCapability: async (capability, action, input = {}, meta = {}) => executeCapability(capability, action, input, meta),
|
||||||
emit: (type, data) => broadcastEvent(type, { pluginId: manifest.id, ...data }),
|
emit: (type, data) => broadcastEvent(type, { pluginId: manifest.id, ...data }),
|
||||||
|
|||||||
Reference in New Issue
Block a user