oa-ai/src/lib/email.ts

68 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Resend } from 'resend'
const resend = new Resend(process.env.RESEND_API_KEY)
export async function sendSetupLinkEmail(
to: string,
username: string,
setupUrl: string,
displayName: string,
) {
const name = displayName || username
const html = `<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body style="margin:0;padding:0;background:#f5f7fa;">
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f5f7fa;padding:40px 0;">
<tr><td align="center">
<table width="480" cellpadding="0" cellspacing="0" style="background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 2px 12px rgba(0,0,0,0.08);">
<tr><td style="background:#2563eb;padding:28px 32px;text-align:center;">
<div style="font-size:18px;font-weight:700;color:#fff;">&#128274; OA 统一门户</div>
</td></tr>
<tr><td style="padding:32px;">
<p style="margin:0 0 16px;font-size:14px;color:#334155;">您好,<strong>${name}</strong></p>
<p style="margin:0 0 24px;font-size:14px;color:#475569;line-height:1.7;">您的 OA 统一门户账号已创建,请点击下方按钮设置登录密码:</p>
<table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom:24px;">
<tr><td align="center">
<a href="${setupUrl}" style="display:inline-block;padding:14px 40px;background:#2563eb;color:#fff;text-decoration:none;border-radius:8px;font-size:16px;font-weight:600;">设置登录密码</a>
</td></tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;">
<tr><td style="padding:9px 16px;width:80px;font-size:13px;color:#64748b;">用户名</td><td style="padding:9px 16px;font-size:14px;font-weight:600;color:#0f172a;">${username}</td></tr>
</table>
<div style="margin-top:24px;padding:14px 16px;background:#fffbeb;border:1px solid #fde68a;border-radius:8px;">
<p style="margin:0;font-size:13px;color:#92400e;line-height:1.6;"><strong>&#9888; 请注意:</strong></p>
<p style="margin:6px 0 0;font-size:13px;color:#92400e;line-height:1.6;">此链接 <strong>24 小时内有效</strong>,过期后需联系管理员重新创建账号。</p>
<p style="margin:6px 0 0;font-size:13px;color:#92400e;line-height:1.6;">修改密码只能通过 OA 统一门户oa.tlyq.ai无法在子站点assets、issue 等)中修改密码。</p>
</div>
<p style="margin:24px 0 0;font-size:12px;color:#94a3b8;">此邮件由系统自动发送,请勿回复。<br>如有疑问,请联系管理员。</p>
</td></tr>
</table>
</td></tr>
</table>
</body>
</html>`
const text = `您好,${name}
您的 OA 统一门户账号已创建,请点击以下链接设置登录密码:
${setupUrl}
用户名:${username}
⚠ 请注意:
此链接 24 小时内有效,过期后需联系管理员重新创建账号。
修改密码只能通过 OA 统一门户oa.tlyq.ai无法在子站点assets、issue 等)中修改密码。
此邮件由系统自动发送,请勿回复。`
await resend.emails.send({
from: 'OA 统一门户 <noreply@tlyq.ai>',
to,
subject: '您的 OA 统一门户账号已创建',
text,
html,
})
}