feat(mail): add smtp email delivery
This commit is contained in:
parent
faddaa91d0
commit
3456b04ed4
25 changed files with 529 additions and 60 deletions
|
|
@ -1,9 +1,26 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { requireAdminSession } from "@/lib/admin/auth";
|
||||
import { saveSmtpSettings } from "@/lib/admin/store";
|
||||
import { saveSmtpSettings, toPublicSmtpSettings } from "@/lib/mail/config";
|
||||
import { sendTestMail } from "@/lib/mail/smtp";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (!await requireAdminSession()) return NextResponse.json({ message: "Nicht autorisiert." }, { status: 401 });
|
||||
await saveSmtpSettings(await request.formData());
|
||||
return new NextResponse(null, { status: 303, headers: { Location: "/admin/smtp?saved=1" } });
|
||||
const form = await request.formData();
|
||||
const action = String(form.get("action") ?? "save");
|
||||
|
||||
if (action === "test") {
|
||||
const settings = await saveSmtpSettings(form);
|
||||
const result = await sendTestMail();
|
||||
return NextResponse.json({
|
||||
message: result.ok ? "Test-E-Mail wurde gesendet." : result.error ?? "Test-E-Mail fehlgeschlagen.",
|
||||
ok: result.ok,
|
||||
settings: toPublicSmtpSettings(settings),
|
||||
}, { status: result.ok ? 200 : 400 });
|
||||
}
|
||||
|
||||
const settings = await saveSmtpSettings(form);
|
||||
return NextResponse.json({
|
||||
message: "SMTP-Konfiguration gespeichert.",
|
||||
settings: toPublicSmtpSettings(settings),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue