26 lines
671 B
TypeScript
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;
|
|
}
|
|
}
|
|
}
|