mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
Bugfixes/email smtp issues (#13154)
This commit is contained in:
parent
8daf7c8452
commit
c9d01da916
6 changed files with 39 additions and 19 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
17
server/src/modules/email-listener/module.ts
Normal file
17
server/src/modules/email-listener/module.ts
Normal 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: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue