mirror of
https://github.com/twentyhq/twenty.git
synced 2024-09-11 23:37:21 +03:00
Update logging for smtp emails (#3536)
This commit is contained in:
parent
f1b3d1537a
commit
e45a825a3a
@ -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`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user