issue # 이메일 인증 코드 발송 로직 구현

This commit is contained in:
geonhee-min
2025-11-21 16:21:07 +09:00
parent 0170421d16
commit 6cd0361375
13 changed files with 118 additions and 6 deletions

0
src/util/converter.ts Normal file
View File

5
src/util/generator.ts Normal file
View File

@@ -0,0 +1,5 @@
export class Generator {
static getVerificationCode() {
return Math.random().toString().slice(2, 8);
}
}

View File

@@ -0,0 +1,9 @@
import { Module, Global } from '@nestjs/common';
import { MailerService } from './mailer.service';
@Global()
@Module({
providers: [MailerService],
exports: [MailerService]
})
export class MailerModule {}

View File

@@ -0,0 +1,46 @@
import { Injectable } from '@nestjs/common';
import nodemailer from 'nodemailer';
import { google } from 'googleapis';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
@Injectable()
export class MailerService {
private oauth2Client = new google.auth.OAuth2(
process.env.GMAIL_CLIENT_ID,
process.env.GMAIL_CLIENT_SECRET,
'https://developers.google.com/oauthplayground'
);
constructor() {
this.oauth2Client.setCredentials({
refresh_token: process.env.GMAIL_REFRESH_TOKEN
});
}
async sendMail(to: string, subject: string, html: string) {
const accessToken = await this.oauth2Client.getAccessToken();
console.log(accessToken);
const options: SMTPTransport.Options = {
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: process.env.GMAIL_USER,
clientId: process.env.GMAIL_CLIENT_ID,
clientSecret: process.env.GMAIL_CLIENT_SECRET,
refreshToken: process.env.GMAIL_REFRESH_TOKEN,
accessToken: accessToken?.token || ''
}
}
const transporter = nodemailer.createTransport(options);
return transporter.sendMail({
from: `Scheduler ${process.env.GMAIL_USER}>`,
to,
subject,
html
})
}
}