summary refs log tree commit diff
diff options
context:
space:
mode:
authorLisa Marie Maginnis <me@lisamarie.pro>2026-03-13 16:14:04 +0100
committerRory& <root@rory.gay>2026-03-15 14:49:37 +0100
commit63effc3887983a4e00754bdcfddbadeb5f4cfbe2 (patch)
tree2777c8ec7ba15392bba25d095f06ef7ff279ca1e
parentadded missing author to replies (diff)
downloadserver-ts-63effc3887983a4e00754bdcfddbadeb5f4cfbe2.tar.xz
Added two new configuration options for SMTP: "starttls" and
"allowInsecure".

smtp.starttls will enable or disable STARTTLS
when "secure" is set to false (otherwise it does nothing).

smtp.allowInsecure will allow self-signed certificates if
set to true for both smtp.secure and smtp.starttls options.
-rw-r--r--src/util/config/types/subconfigurations/email/SMTP.ts2
-rw-r--r--src/util/util/email/clients/SMTPEmailClient.ts41
2 files changed, 24 insertions, 19 deletions
diff --git a/src/util/config/types/subconfigurations/email/SMTP.ts b/src/util/config/types/subconfigurations/email/SMTP.ts

index 85c286a3..cf81aec9 100644 --- a/src/util/config/types/subconfigurations/email/SMTP.ts +++ b/src/util/config/types/subconfigurations/email/SMTP.ts
@@ -20,6 +20,8 @@ export class SMTPConfiguration { host: string | null = null; port: number | null = null; secure: boolean | null = null; + starttls: boolean = false; + allowInsecure: boolean = false; username: string | null = null; password: string | null = null; } diff --git a/src/util/util/email/clients/SMTPEmailClient.ts b/src/util/util/email/clients/SMTPEmailClient.ts
index 5c469e0f..278a4198 100644 --- a/src/util/util/email/clients/SMTPEmailClient.ts +++ b/src/util/util/email/clients/SMTPEmailClient.ts
@@ -34,7 +34,7 @@ export class SMTPEmailClient extends BaseEmailClient { return; } // get configuration - const { host, port, secure, username, password } = Config.get().email.smtp; + const { host, port, secure, starttls, allowInsecure, username, password } = Config.get().email.smtp; // ensure all required configuration values are set if (!host || !port || secure === null) return console.error("[Email] SMTP has not been configured correctly."); @@ -45,24 +45,27 @@ export class SMTPEmailClient extends BaseEmailClient { ); /* Allow for SMTP relays with and without username/passwords (IE: Smarthosts/Local Relays, etc) */ - let nodemailer_opts: unknown; - if(!username || !password) { - nodemailer_opts = { - host, - port, - secure, - }; - } else { - nodemailer_opts = { - host, - port, - secure, - auth: { - user: username, - pass: password, - }, - }; - } + const nodemailer_opts = { + host: host, + port: port, + secure: secure, + ...(starttls ? { requireTLS: true } : { ignoreTLS: true }), + ...(allowInsecure + ? { + tls: { + rejectUnauthorized: false, + }, + } + : {}), + ...(username && password + ? { + auth: { + user: username, + pass: password, + }, + } + : {}), + }; // construct the transporter // eslint-disable-next-line @typescript-eslint/ban-ts-comment