mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-26 06:32:03 +10:00
refactor(v4.0.0-alpha): beginning of a new era
This commit is contained in:
36
apps/server/src/mail/mail.module.ts
Normal file
36
apps/server/src/mail/mail.module.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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 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 {
|
||||
transport: smtpUrl || emptyTransporter,
|
||||
defaults: { from: "Reactive Resume <noreply@rxresu.me>" },
|
||||
};
|
||||
},
|
||||
}),
|
||||
],
|
||||
providers: [MailService],
|
||||
exports: [MailService],
|
||||
})
|
||||
export class MailModule {}
|
||||
24
apps/server/src/mail/mail.service.ts
Normal file
24
apps/server/src/mail/mail.service.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { ISendMailOptions, MailerService } from "@nestjs-modules/mailer";
|
||||
|
||||
import { Config } from "@/server/config/schema";
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
constructor(
|
||||
private readonly configService: ConfigService<Config>,
|
||||
private readonly mailerService: MailerService,
|
||||
) {}
|
||||
|
||||
async sendEmail(options: ISendMailOptions) {
|
||||
const smtpUrl = this.configService.get("SMTP_URL");
|
||||
|
||||
// If `SMTP_URL` is not set, log the email to the console
|
||||
if (!smtpUrl) {
|
||||
return Logger.log(options, "MailService#sendEmail");
|
||||
}
|
||||
|
||||
return this.mailerService.sendMail(options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user