You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

22 lines
785 B

import { requireAdmin } from "#server/utils/admin-guard";
import { sendMail } from "#server/service/email";
export default defineWrappedResponseHandler(async (event) => {
await requireAdmin(event);
const body = await readBody<{ to: string; subject?: string; text?: string }>(event);
if (!body.to) {
throw createError({ statusCode: 400, statusMessage: "收件人地址不能为空" });
}
const result = await sendMail({
to: body.to,
subject: body.subject || "测试邮件 - Person Panel",
text: body.text || "这是一封来自 Person Panel 的测试邮件。如果你收到此邮件,说明邮件配置正确。",
});
if (result.success) {
return R.success(result);
}
throw createError({ statusCode: 400, statusMessage: result.message });
});