Allow for unsecure SMTP settings for local unencrypted smtp relays (#10605)
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. <mark>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.</mark> **ignoreTLS** – <mark>if this is true and secure is false then TLS is not used even if the server supports STARTTLS extension.</mark> --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -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`);
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
Reference in New Issue
Block a user