Skip to content

Allow more control over TLS settings for nodemailer (STARTTLS and self-signed certificates)#1590

Merged
TheArcaneBrony merged 1 commit intospacebarchat:masterfrom
e-lisa:smtp-hotfix
Mar 15, 2026
Merged

Allow more control over TLS settings for nodemailer (STARTTLS and self-signed certificates)#1590
TheArcaneBrony merged 1 commit intospacebarchat:masterfrom
e-lisa:smtp-hotfix

Conversation

@e-lisa
Copy link

@e-lisa e-lisa commented Mar 13, 2026

Problem

Nodemailer still upgrades connections to TLS via STARTTLS even if smtp.secure is set to false in the configuration file. Furthermore there is no way to accept self signed certificates for both connections that start with TLS (secure == true) or connections that upgrade to TLS via STARTTLS.

Solution

Add two new configuration options to better manage nodemailer's usage of TLS.

  • smtp.starttls - When set to true will set requireTLS to true in the nodemailer initialization, even if STARTTLS is not advertised. If set to false will set ignoreTLS to true which will prevent nodemailer from upgrading to TLS via STARTTLS. Default to false.
  • smtp.allowInsecure - When set to true will allow insecure certificates (self signed, expired, etc) to be accepted by nodemailer. Defaults to false.

By adding these options it will allow more flexibility when configuring SMTP settings for both instance owners and developers and solves the problem outlined above.

Source: https://nodemailer.com/usage

@CyberL1
Copy link
Member

CyberL1 commented Mar 13, 2026

This... doesn't "fix" anything? I mean, if a variable is the same as the key, it can be omitted

@e-lisa
Copy link
Author

e-lisa commented Mar 13, 2026

This... doesn't "fix" anything? I mean, if a variable is the same as the key, it can be omitted

Ooops, this PR is missing part of it! But we still will need to say secure: secure or it ignores any additional TLS settings like ignoreTLS/requireTLS - I'll upload the missing chunks when I get home!

Even so, we must include the secure: secure part of this PR or it wont work. Without ignoreTLS we end up with the client still trying STARTTLS even with Secure set to false, causing Email to fail to init, and no outbound mail (password reset, email verification) can run:

[Email] Initializing smtp transport...
[Email] SMTP verification failed: [Error: 006D0F1B717F0000:error:0A00010B:SSL routines:tls_validate_record_header:wrong version number:../deps/openssl/openssl/ssl/record/methods/tlsany_meth.c:77:

Server starts and inits email with secure set to false (with fix):

[Email] Initializing smtp transport...
[Email] smtp transport initialized.

@e-lisa
Copy link
Author

e-lisa commented Mar 13, 2026

This PR is now ready for review

I've added the proper fixes (via ternary operator). After more testing we dont really need to set "host" / "port" / "secure" explicitly - but i think we should for future readability - since there are more features of nodemailer we might want to take advantage of in the future.

With this fix I can confirm that disabling TLS actually works now:

[Email] Initializing smtp transport...
[Email] smtp transport initialized.

I think it is beyond the scope of this PR, but maybe in the future we may want to consider an option for STARTTLS as as separate configuration option that can be toggled when secure == false

Added new configuration options

@e-lisa e-lisa changed the title fixed calls to init smtp via nodemailer Allow more control over TLS settings for nodemailer (STARTTLS and self-signed certificates) Mar 14, 2026
"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.
@TheArcaneBrony TheArcaneBrony merged commit 63effc3 into spacebarchat:master Mar 15, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants