Files
dsc-api/src/modules/utils/providers/email.service.ts
T
2025-01-20 09:38:43 +03:30

26 lines
671 B
TypeScript

import { Injectable, Logger } from "@nestjs/common";
import { MailerService } from "@nestjs-modules/mailer";
@Injectable()
export class EmailService {
private readonly logger = new Logger(EmailService.name);
constructor(private readonly mailerService: MailerService) {}
async sendEmail(to: string, subject: string) {
try {
await this.mailerService.sendMail({
to: to,
from: "noreply@nestjs.com",
subject: subject,
template: "otp",
context: {
//Data to be sent to template
},
});
} catch (error) {
this.logger.error("Email sending failed:", error);
return false;
}
}
}