Bugfixes/email smtp issues (#13154)

This commit is contained in:
Rohan Lahori 2025-07-02 17:16:39 +05:30 committed by GitHub
parent 8daf7c8452
commit c9d01da916
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 19 deletions

View file

@ -53,6 +53,7 @@ import { SampleDBScheduler } from '@modules/data-sources/schedulers/sample-db.sc
import { SessionScheduler } from '@modules/session/scheduler';
import { AuditLogsClearScheduler } from '@modules/audit-logs/scheduler';
import { ModulesModule } from '@modules/modules/module';
import { EmailListenerModule } from '@modules/email-listener/module';
export class AppModule implements OnModuleInit {
static async register(configs: { IS_GET_CONTEXT: boolean }): Promise<DynamicModule> {
// Load static and dynamic modules
@ -113,6 +114,7 @@ export class AppModule implements OnModuleInit {
await AppGitModule.register(configs),
await CrmModule.register(configs),
await OrganizationPaymentModule.register(configs),
await EmailListenerModule.register(configs),
];
return {

View file

@ -1,9 +1,8 @@
import { Injectable } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { Logger } from 'nestjs-pino';
import { EmailEventPayload } from './constants';
import { EmailEventPayload, EMAIL_EVENTS } from '@modules/email/constants';
import { EmailService } from '@modules/email/service';
import { EMAIL_EVENTS } from './constants';
@Injectable()
export class EmailListener {
@ -15,7 +14,6 @@ export class EmailListener {
@OnEvent('emailEvent')
async handleEmailEvent(eventData: EmailEventPayload) {
const { type, payload } = eventData;
try {
switch (type) {
case EMAIL_EVENTS.SEND_WELCOME_EMAIL:

View file

@ -0,0 +1,17 @@
import { DynamicModule } from '@nestjs/common';
import { SubModule } from '@modules/app/sub-module';
import { EmailModule } from '@modules/email/module';
import { getImportPath } from '@modules/app/constants';
export class EmailListenerModule extends SubModule {
static async register(configs?: { IS_GET_CONTEXT: boolean }): Promise<DynamicModule> {
const importPath = await getImportPath(configs?.IS_GET_CONTEXT);
const { EmailListener } = await import(`${importPath}/email-listener/listener`);
return {
module: EmailListenerModule,
imports: [await EmailModule.register(configs)],
providers: [EmailListener],
exports: [],
};
}
}

View file

@ -10,7 +10,6 @@ export class EmailModule extends SubModule {
const importPath = await getImportPath(configs?.IS_GET_CONTEXT);
const { EmailService } = await import(`${importPath}/email/service`);
const { EmailUtilService } = await import(`${importPath}/email/util.service`);
const { EmailListener } = await import(`${importPath}/email/listener`);
return {
module: EmailModule,
imports: [
@ -18,8 +17,8 @@ export class EmailModule extends SubModule {
await DataSourcesModule.register(configs),
await SMTPModule.register(configs),
],
providers: [EmailService, EmailListener, EmailUtilService],
exports: [EmailListener, EmailUtilService],
providers: [EmailService, EmailUtilService],
exports: [EmailUtilService, EmailService],
};
}
}

View file

@ -9,7 +9,6 @@ import {
} from '@modules/email/dto';
import { EmailUtilService } from './util.service';
import { IEmailService } from './interfaces/IService';
import { INSTANCE_SYSTEM_SETTINGS } from '@modules/instance-settings/constants';
import { WhiteLabellingUtilService } from '@modules/white-labelling/util.service';
handlebars.registerHelper('capitalize', function (value) {
@ -29,15 +28,6 @@ export class EmailService implements IEmailService {
protected WHITE_LABEL_TEXT;
protected WHITE_LABEL_LOGO;
protected SUB_PATH;
protected SMTP: {
[INSTANCE_SYSTEM_SETTINGS.SMTP_ENABLED]: boolean;
[INSTANCE_SYSTEM_SETTINGS.SMTP_DOMAIN]: string;
[INSTANCE_SYSTEM_SETTINGS.SMTP_PORT]: string;
[INSTANCE_SYSTEM_SETTINGS.SMTP_USERNAME]: string;
[INSTANCE_SYSTEM_SETTINGS.SMTP_PASSWORD]: string;
[INSTANCE_SYSTEM_SETTINGS.SMTP_FROM_EMAIL]: string;
[INSTANCE_SYSTEM_SETTINGS.SMTP_ENV_CONFIGURED]: boolean;
};
protected defaultWhiteLabelState: boolean;
constructor(
@ -63,14 +53,13 @@ export class EmailService implements IEmailService {
async init(organizationId?: string | null) {
const whiteLabelSettings = await this.emailUtilService.retrieveWhiteLabelSettings(null);
this.SMTP = await this.emailUtilService.retrieveSmtpSettings();
this.WHITE_LABEL_TEXT = whiteLabelSettings?.white_label_text;
this.WHITE_LABEL_LOGO = whiteLabelSettings?.white_label_logo;
this.defaultWhiteLabelState = whiteLabelSettings?.default;
}
protected compileTemplate(templatePath: string, templateData: object) {
this.emailUtilService.compileTemplate(templatePath, templateData);
return this.emailUtilService.compileTemplate(templatePath, templateData);
}
protected stripTrailingSlash(hostname: string) {
@ -88,6 +77,7 @@ export class EmailService implements IEmailService {
redirectTo,
} = payload;
await this.init(organizationId);
await this.emailUtilService.init(organizationId);
const isOrgInvite = organizationInvitationToken && sender && organizationName;
const inviteUrl = generateInviteURL(invitationtoken, organizationInvitationToken, organizationId, null, redirectTo);
const subject = isOrgInvite ? `Welcome to ${organizationName || 'ToolJet'}` : 'Set up your account!';

View file

@ -36,7 +36,11 @@ export class EmailUtilService implements IEmailUtilService {
constructor(
protected readonly whiteLabellingUtilService: WhiteLabellingUtilService,
protected readonly smtpUtilService: SMTPUtilService
) {}
) {
this.TOOLJET_HOST = this.stripTrailingSlash(process.env.TOOLJET_HOST);
this.SUB_PATH = process.env.SUB_PATH;
this.NODE_ENV = process.env.NODE_ENV || 'development';
}
async retrieveWhiteLabelSettings(organizationId?: string | null): Promise<any> {
const whiteLabelSetting = await this.whiteLabellingUtilService.getProcessedSettings(organizationId);
@ -253,4 +257,14 @@ export class EmailUtilService implements IEmailUtilService {
whiteLabelLogo: DEFAULT_WHITE_LABELLING_SETTINGS.white_label_logo,
});
}
protected stripTrailingSlash(hostname: string) {
return hostname?.endsWith('/') ? hostname.slice(0, -1) : hostname;
}
async init(organizationId?: string | null) {
const whiteLabelSettings = await this.retrieveWhiteLabelSettings(null);
this.SMTP = await this.retrieveSmtpSettings();
this.WHITE_LABEL_TEXT = whiteLabelSettings?.white_label_text;
this.WHITE_LABEL_LOGO = whiteLabelSettings?.white_label_logo;
this.defaultWhiteLabelState = whiteLabelSettings?.default;
}
}