File size: 1,062 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import { Logger, Module } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { MailerModule } from "@nestjs-modules/mailer";
import * as nodemailer from "nodemailer";
import { Config } from "@/server/config/schema";
import { MailService } from "./mail.service";
const emptyTransporter = nodemailer.createTransport({});
@Module({
imports: [
MailerModule.forRootAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService<Config>) => {
const from = configService.get("MAIL_FROM");
const smtpUrl = configService.get("SMTP_URL");
if (!smtpUrl) {
Logger.warn(
"Since `SMTP_URL` is not set, emails would be logged to the console instead. This is not recommended for production environments.",
"MailModule",
);
}
return {
defaults: { from },
transport: smtpUrl || emptyTransporter,
};
},
}),
],
providers: [MailService],
exports: [MailService],
})
export class MailModule {}
|