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',