2025-06-16 15:53:15 +05:30
|
|
|
import { MailerModule } from '@nestjs-modules/mailer';
|
|
|
|
|
import { Module } from '@nestjs/common';
|
2025-07-02 17:37:04 +05:30
|
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
|
|
import { join } from 'path';
|
|
|
|
|
import * as Joi from 'joi';
|
|
|
|
|
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
|
2025-06-16 15:53:15 +05:30
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
|
imports: [
|
2025-07-02 17:37:04 +05:30
|
|
|
ConfigModule.forRoot({
|
|
|
|
|
isGlobal: true,
|
|
|
|
|
validationSchema: Joi.object({
|
|
|
|
|
MAIL_USER: Joi.string().required(),
|
|
|
|
|
MAIL_PASS: Joi.string().required(),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
MailerModule.forRootAsync({
|
|
|
|
|
imports: [ConfigModule],
|
|
|
|
|
useFactory: (configService: ConfigService) => ({
|
|
|
|
|
transport: {
|
|
|
|
|
host: 'smtp.gmail.com',
|
|
|
|
|
port: 587,
|
|
|
|
|
// ignoreTLS: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
auth: {
|
|
|
|
|
user: configService.get<string>('MAIL_USER'),
|
|
|
|
|
pass: configService.get<string>('MAIL_PASS'),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
defaults: {
|
|
|
|
|
from: `"Carnet APP" <${configService.get<string>('MAIL_USER')}>`,
|
|
|
|
|
},
|
|
|
|
|
template: {
|
|
|
|
|
dir: join(__dirname, '../../..', 'public', 'mail-templates'),
|
|
|
|
|
adapter: new HandlebarsAdapter(), // import from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'
|
|
|
|
|
options: {
|
|
|
|
|
strict: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
inject: [ConfigService],
|
2025-06-16 15:53:15 +05:30
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
})
|
2025-07-02 17:37:04 +05:30
|
|
|
|
2025-06-16 15:53:15 +05:30
|
|
|
export class MailModule { }
|