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),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { addContactInquiry } from "@/lib/admin/store";
|
||||
import { sendContactInquiryMail } from "@/lib/mail/smtp";
|
||||
|
||||
function text(value: FormDataEntryValue | null) {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
|
|
@ -16,7 +17,8 @@ export async function POST(request: Request) {
|
|||
return NextResponse.json({ message: "Bitte füllen Sie alle Pflichtfelder aus." }, { status: 400 });
|
||||
}
|
||||
|
||||
await addContactInquiry(form);
|
||||
const inquiry = await addContactInquiry(form);
|
||||
await sendContactInquiryMail(inquiry);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Ihre Nachricht wurde erfasst. Sie erhalten eine Rückmeldung.",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { adminConfigurationStatus, appVersion, checkStorage } from "@/lib/runtime/config";
|
||||
import { getSmtpSettings, isSmtpConfigured } from "@/lib/mail/config";
|
||||
|
||||
export async function GET() {
|
||||
let storage = "ok";
|
||||
|
|
@ -10,11 +11,14 @@ export async function GET() {
|
|||
storage = "error";
|
||||
}
|
||||
|
||||
const smtpSettings = await getSmtpSettings();
|
||||
|
||||
return NextResponse.json({
|
||||
status: storage === "ok" ? "ok" : "error",
|
||||
version: appVersion,
|
||||
storage,
|
||||
admin: adminConfigurationStatus(),
|
||||
smtp: isSmtpConfigured(smtpSettings) ? "configured" : "missing",
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { addRepairInquiry } from "@/lib/admin/store";
|
||||
import { sendRepairInquiryMail } from "@/lib/mail/smtp";
|
||||
|
||||
function required(value: FormDataEntryValue | null) {
|
||||
return typeof value === "string" && value.trim().length > 0;
|
||||
|
|
@ -19,7 +20,8 @@ export async function POST(request: Request) {
|
|||
return NextResponse.json({ message: "Bitte füllen Sie alle Pflichtfelder aus." }, { status: 400 });
|
||||
}
|
||||
|
||||
await addRepairInquiry(form);
|
||||
const inquiry = await addRepairInquiry(form);
|
||||
await sendRepairInquiryMail(inquiry);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Ihre Reparaturanfrage wurde erfasst. Sie erhalten nach Prüfung eine Rückmeldung.",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue