nest-modules / mailer

📨 A mailer module for Nest framework (node.js)
https://nest-modules.github.io/mailer/
MIT License
846 stars 177 forks source link

Make transporter in MailService public to verify if auth is good #886

Closed GFoniX closed 10 months ago

GFoniX commented 2 years ago

Hello,

I am using a module to send email. So I installed the module @nestjs-modules/mailer and then I make my config to send mail.

But the things are I want to test if I put the good credential and SMTP host. In node mailer there is a function transporter. Verify() that verify if the information is correct.

But in the mailService I can't access to the transporter.

mailer.service.d.ts in the @nestjs-modules/mailer export declare class MailerService { private readonly mailerOptions; private readonly transportFactory; private transporter; private transporters; private templateAdapter; private initTemplateAdapter; constructor(mailerOptions: MailerOptions, transportFactory: IMailerTransportFactory); sendMail(sendMailOptions: ISendMailOptions): Promise; addTransporter(transporterName: string, config: string | smtpTransport | smtpTransport.Options): string; }

I don't know if there is another solution, but for me, it's will be nice to have the transporter in public? Like this I could test if my email information is correct

koorya commented 1 year ago

Same issue, just need to close transporter after module desstroy. Now I use this

import { Transporter } from 'nodemailer';

@Module({
  imports: [MailerModule.forRoot({  ...  })],
  exports: [MailerModule],
})
class CustomMailerModule implements OnModuleDestroy {
  constructor(
    @Inject(MailerService)
    private readonly mailerService: MailerService,
  ) {}
  async onModuleDestroy() {
    (this.mailerService['transporter'] as Transporter).close();
  }
}