mirror of
https://github.com/andwati/nestjs-auth-email-phone.git
synced 2026-11-05 19:32:16 +00:00
26 lines
656 B
TypeScript
26 lines
656 B
TypeScript
// mail.service.ts
|
|
import { Injectable } from '@nestjs/common';
|
|
import * as nodemailer from 'nodemailer';
|
|
|
|
@Injectable()
|
|
export class MailService {
|
|
private transporter = nodemailer.createTransport({
|
|
host: process.env.SMTP_HOST,
|
|
port: Number(process.env.SMTP_PORT),
|
|
secure: true,
|
|
auth: {
|
|
user: process.env.SMTP_USER,
|
|
pass: process.env.SMTP_PASS
|
|
}
|
|
});
|
|
|
|
async sendOtp(email: string, otp: string) {
|
|
await this.transporter.sendMail({
|
|
from: '"Your App" <[email protected]>',
|
|
to: email,
|
|
subject: 'Your OTP Code',
|
|
text: `Your verification code is ${otp}. It expires in 5 minutes.`
|
|
});
|
|
}
|
|
}
|