mirror of
https://github.com/lingble/twenty.git
synced 2025-11-01 21:27:58 +00:00
Update logging for smtp emails (#3536)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { createTransport, Transporter, SendMailOptions } from 'nodemailer';
|
||||
import SMTPConnection from 'nodemailer/lib/smtp-connection';
|
||||
|
||||
import { EmailDriver } from 'src/integrations/email/drivers/interfaces/email-driver.interface';
|
||||
|
||||
export class SmtpDriver implements EmailDriver {
|
||||
private readonly logger = new Logger(SmtpDriver.name);
|
||||
private transport: Transporter;
|
||||
|
||||
constructor(options: SMTPConnection.Options) {
|
||||
@@ -11,6 +14,13 @@ export class SmtpDriver implements EmailDriver {
|
||||
}
|
||||
|
||||
async send(sendMailOptions: SendMailOptions): Promise<void> {
|
||||
await this.transport.sendMail(sendMailOptions);
|
||||
this.transport
|
||||
.sendMail(sendMailOptions)
|
||||
.then(() =>
|
||||
this.logger.log(`Email to '${sendMailOptions.to}' successfully sent`),
|
||||
)
|
||||
.catch((err) =>
|
||||
this.logger.error(`sending email to '${sendMailOptions.to}': ${err}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { SendMailOptions } from 'nodemailer';
|
||||
|
||||
@@ -8,11 +8,9 @@ import { EmailSenderService } from 'src/integrations/email/email-sender.service'
|
||||
|
||||
@Injectable()
|
||||
export class EmailSenderJob implements MessageQueueJob<SendMailOptions> {
|
||||
private readonly logger = new Logger(EmailSenderJob.name);
|
||||
constructor(private readonly emailSenderService: EmailSenderService) {}
|
||||
|
||||
async handle(data: SendMailOptions): Promise<void> {
|
||||
await this.emailSenderService.send(data);
|
||||
this.logger.log(`Email to ${data.to} sent`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user