From f8772d205d9f80ae823215bebd998cd7571d3855 Mon Sep 17 00:00:00 2001
From: clivinghouse <79345446+clivinghouse@users.noreply.github.com>
Date: Mon, 10 Mar 2025 08:30:38 -0400
Subject: [PATCH] Allow for unsecure SMTP settings for local unencrypted smtp
relays (#10605)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This update provides the flexibility for users to configure SMTP for
local instances where encryption is not required. For environments using
an unencrypted SMTP relay or similar local instances that are not open
to the public, the end user can now choose to disable encryption. This
ensures flexibility in the configuration while still maintaining the
option for secure SMTP connections in other environments.
### From [NodeMailer](https://nodemailer.com/smtp/#tls-options)
**secure** – if true the connection will use TLS when connecting to
server. If false (the default) then TLS is used if server supports
the STARTTLS extension. In most cases set this value to true if you are
connecting to port 465. For port 587 or 25 keep it false.
**ignoreTLS** – if this is true and secure is false then TLS is
not used even if the server supports STARTTLS extension.
---------
Co-authored-by: Félix Malfait
Co-authored-by: Félix Malfait
---
.../email/email.module-factory.ts | 26 ++++++++++++-------
.../environment/environment-variables.ts | 9 +++++++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/packages/twenty-server/src/engine/core-modules/email/email.module-factory.ts b/packages/twenty-server/src/engine/core-modules/email/email.module-factory.ts
index 447d857e8..4d79640f4 100644
--- a/packages/twenty-server/src/engine/core-modules/email/email.module-factory.ts
+++ b/packages/twenty-server/src/engine/core-modules/email/email.module-factory.ts
@@ -11,29 +11,37 @@ export const emailModuleFactory = (
const driver = environmentService.get('EMAIL_DRIVER');
switch (driver) {
- case EmailDriver.Logger: {
- return;
- }
+ case EmailDriver.Logger:
+ return {};
+
case EmailDriver.Smtp: {
+ const options: EmailModuleOptions = {};
+
const host = environmentService.get('EMAIL_SMTP_HOST');
const port = environmentService.get('EMAIL_SMTP_PORT');
const user = environmentService.get('EMAIL_SMTP_USER');
const pass = environmentService.get('EMAIL_SMTP_PASSWORD');
+ const noTLS = environmentService.get('EMAIL_SMTP_NO_TLS');
- if (!(host && port)) {
+ if (!host || !port) {
throw new Error(
- `${driver} email driver requires host: ${host} and port: ${port} to be defined, check your .env file`,
+ `${driver} email driver requires host and port to be defined, check your .env file`,
);
}
- const auth = user && pass ? { user, pass } : undefined;
+ options.host = host;
+ options.port = port;
- if (auth) {
- return { host, port, auth };
+ if (user && pass) options.auth = { user, pass };
+
+ if (noTLS) {
+ options.secure = false;
+ options.ignoreTLS = true;
}
- return { host, port };
+ return options;
}
+
default:
throw new Error(`Invalid email driver (${driver}), check your .env file`);
}
diff --git a/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts b/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
index 186f31351..fa0d2391c 100644
--- a/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
+++ b/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
@@ -289,6 +289,15 @@ export class EnvironmentVariables {
})
EMAIL_SMTP_HOST: string;
+ @EnvironmentVariablesMetadata({
+ group: EnvironmentVariablesGroup.EmailSettings,
+ description: 'Use unsecure connection for SMTP',
+ })
+ @CastToBoolean()
+ @IsOptional()
+ @IsBoolean()
+ EMAIL_SMTP_NO_TLS = false;
+
@EnvironmentVariablesMetadata({
group: EnvironmentVariablesGroup.EmailSettings,
description: 'SMTP port for sending emails',