diff --git a/.env.example b/.env.example index d8547a701..7c4124c11 100644 --- a/.env.example +++ b/.env.example @@ -35,6 +35,7 @@ MICROSOFT_SCOPE="user.read" MICROSOFT_TENANT="common" # Mailer config +MAILER_SMTP_ENABLE="true" MAILER_SMTP_URL="smtps://user@domain.com:pass@smtp.domain.com" MAILER_ADDRESS_FROM='"From Name Here" ' diff --git a/packages/hoppscotch-backend/src/infra-config/helper.ts b/packages/hoppscotch-backend/src/infra-config/helper.ts index 9238788a6..de358a947 100644 --- a/packages/hoppscotch-backend/src/infra-config/helper.ts +++ b/packages/hoppscotch-backend/src/infra-config/helper.ts @@ -75,6 +75,10 @@ export async function getDefaultInfraConfigs(): Promise< // Prepare rows for 'infra_config' table with default values (from .env) for each 'name' const infraConfigDefaultObjs: { name: InfraConfigEnum; value: string }[] = [ + { + name: InfraConfigEnum.MAILER_SMTP_ENABLE, + value: process.env.MAILER_SMTP_ENABLE ?? 'true', + }, { name: InfraConfigEnum.MAILER_SMTP_URL, value: process.env.MAILER_SMTP_URL, diff --git a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts index a6e5f8186..4bc9cb70a 100644 --- a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts +++ b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts @@ -363,6 +363,13 @@ export class InfraConfigService implements OnModuleInit { ) { for (let i = 0; i < infraConfigs.length; i++) { switch (infraConfigs[i].name) { + case InfraConfigEnum.MAILER_SMTP_ENABLE: + if ( + infraConfigs[i].value !== 'true' && + infraConfigs[i].value !== 'false' + ) + return E.left(INFRA_CONFIG_INVALID_INPUT); + break; case InfraConfigEnum.MAILER_SMTP_URL: const isValidUrl = validateSMTPUrl(infraConfigs[i].value); if (!isValidUrl) return E.left(INFRA_CONFIG_INVALID_INPUT); diff --git a/packages/hoppscotch-backend/src/types/InfraConfig.ts b/packages/hoppscotch-backend/src/types/InfraConfig.ts index 8c02929bc..82354b91f 100644 --- a/packages/hoppscotch-backend/src/types/InfraConfig.ts +++ b/packages/hoppscotch-backend/src/types/InfraConfig.ts @@ -1,4 +1,5 @@ export enum InfraConfigEnum { + MAILER_SMTP_ENABLE = 'MAILER_SMTP_ENABLE', MAILER_SMTP_URL = 'MAILER_SMTP_URL', MAILER_ADDRESS_FROM = 'MAILER_ADDRESS_FROM',