This commit is contained in:
parent
3227bc6059
commit
2b63137217
2 changed files with 26 additions and 0 deletions
|
|
@ -134,6 +134,17 @@ export class EnvironmentService {
|
||||||
return this.configService.get<string>('MAIL_FROM_NAME', 'Docmost');
|
return this.configService.get<string>('MAIL_FROM_NAME', 'Docmost');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMailBlockedRecipientDomains(): string[] {
|
||||||
|
const raw = this.configService.get<string>(
|
||||||
|
'MAIL_BLOCKED_RECIPIENT_DOMAINS',
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
return raw
|
||||||
|
.split(',')
|
||||||
|
.map((d) => d.trim().toLowerCase())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
getSmtpHost(): string {
|
getSmtpHost(): string {
|
||||||
return this.configService.get<string>('SMTP_HOST');
|
return this.configService.get<string>('SMTP_HOST');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ export class MailService {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async sendEmail(message: MailMessage): Promise<void> {
|
async sendEmail(message: MailMessage): Promise<void> {
|
||||||
|
if (this.isRecipientBlocked(message.to)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.template) {
|
if (message.template) {
|
||||||
// in case this method is used directly. we do not send the tsx template from queue
|
// in case this method is used directly. we do not send the tsx template from queue
|
||||||
message.html = await render(message.template, {
|
message.html = await render(message.template, {
|
||||||
|
|
@ -35,6 +39,10 @@ export class MailService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendToQueue(message: MailMessage): Promise<void> {
|
async sendToQueue(message: MailMessage): Promise<void> {
|
||||||
|
if (this.isRecipientBlocked(message.to)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.template) {
|
if (message.template) {
|
||||||
// transform the React object because it gets lost when sent via the queue
|
// transform the React object because it gets lost when sent via the queue
|
||||||
message.html = await render(message.template, {
|
message.html = await render(message.template, {
|
||||||
|
|
@ -47,4 +55,11 @@ export class MailService {
|
||||||
}
|
}
|
||||||
await this.emailQueue.add(QueueJob.SEND_EMAIL, message);
|
await this.emailQueue.add(QueueJob.SEND_EMAIL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isRecipientBlocked(to: string): boolean {
|
||||||
|
const blocked = this.environmentService.getMailBlockedRecipientDomains();
|
||||||
|
if (blocked.length === 0) return false;
|
||||||
|
const domain = to?.split('@')[1]?.toLowerCase();
|
||||||
|
return !!domain && blocked.includes(domain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue