82 lines
3 KiB
JavaScript
82 lines
3 KiB
JavaScript
/**
|
|
* 이메일 발송 서비스 (Resend API)
|
|
* 인증 이메일 발송
|
|
*/
|
|
|
|
import { Resend } from "resend";
|
|
|
|
const RESEND_API_KEY = process.env.RESEND_API_KEY;
|
|
const MAIL_FROM = process.env.MAIL_FROM || "no-reply@caadiq.co.kr";
|
|
const SITE_URL = process.env.SITE_URL || "https://minecraft.caadiq.co.kr";
|
|
|
|
// Resend 클라이언트 생성
|
|
const resend = new Resend(RESEND_API_KEY);
|
|
|
|
/**
|
|
* 이메일 인증 메일 발송
|
|
*/
|
|
export async function sendVerificationEmail(to, token, name) {
|
|
const verifyUrl = `${SITE_URL}/verify/${token}`;
|
|
|
|
const html = `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<style>
|
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #ffffff; color: #333333; margin: 0; padding: 40px 20px; }
|
|
.container { max-width: 500px; margin: 0 auto; background: #1a1a1a; border-radius: 16px; padding: 40px; border: 1px solid #2a2a2a; }
|
|
.logo { text-align: center; margin-bottom: 30px; }
|
|
.logo-text { font-size: 24px; font-weight: bold; color: #22c55e; }
|
|
h1 { font-size: 20px; margin: 0 0 20px 0; color: #fff; }
|
|
p { line-height: 1.6; margin: 0 0 20px 0; color: #a3a3a3; }
|
|
.button { display: inline-block; background: #22c55e; color: #fff; text-decoration: none; padding: 14px 28px; border-radius: 8px; font-weight: 600; }
|
|
.button:hover { background: #16a34a; }
|
|
.footer { text-align: center; margin-top: 30px; font-size: 12px; color: #666; }
|
|
.link { color: #22c55e; word-break: break-all; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="logo">
|
|
<span class="logo-text">🎮 마인크래프트 서버</span>
|
|
</div>
|
|
<h1>이메일 인증</h1>
|
|
<p>안녕하세요${name ? `, ${name}님` : ""}!</p>
|
|
<p>마인크래프트 서버 대시보드에 가입해주셔서 감사합니다.<br>아래 버튼을 클릭하여 이메일 인증을 완료해주세요.</p>
|
|
<p style="text-align: center; margin: 30px 0;">
|
|
<a href="${verifyUrl}" class="button">이메일 인증하기</a>
|
|
</p>
|
|
<p style="font-size: 13px;">버튼이 작동하지 않으면 아래 링크를 복사해서 브라우저에 붙여넣으세요:</p>
|
|
<p class="link" style="font-size: 12px;">${verifyUrl}</p>
|
|
<div class="footer">
|
|
<p>이 링크는 24시간 동안 유효합니다.</p>
|
|
<p>본인이 가입하지 않았다면 이 메일을 무시해주세요.</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
try {
|
|
const result = await resend.emails.send({
|
|
from: MAIL_FROM,
|
|
to: to,
|
|
subject: "[마인크래프트 서버] 이메일 인증",
|
|
html: html,
|
|
});
|
|
|
|
if (result.error) {
|
|
console.error("[Email] 발송 오류:", result.error);
|
|
throw new Error(result.error.message);
|
|
}
|
|
|
|
console.log(`[Email] 인증 메일 발송 완료: ${to}`);
|
|
return { success: true, messageId: result.data?.id };
|
|
} catch (error) {
|
|
console.error("[Email] 발송 실패:", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export default { sendVerificationEmail };
|