From 42e58fc2fb878bdad04a81c2e3d9ff05963ff269 Mon Sep 17 00:00:00 2001 From: Atridad Lahiji Date: Thu, 23 Jan 2025 16:20:38 -0600 Subject: [PATCH] JMAP --- .env.example | 11 +- package.json | 1 - pnpm-lock.yaml | 9 -- src/components/ContactForm.tsx | 33 ++++- src/pages/api/contact.ts | 259 ++++++++++++++++++++++++++++----- 5 files changed, 253 insertions(+), 60 deletions(-) diff --git a/.env.example b/.env.example index 0493d67..3f227ee 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,4 @@ -SMTP_HOST= -SMTP_PORT=587 -SMTP_SECURE=true -SMTP_USER= -SMTP_PASS= -FROM_EMAIL= -TO_EMAIL= +JMAP_ACCOUNT_ID="" +JMAP_ACCESS_TOKEN="" +FROM_EMAIL="" +TO_EMAIL="" diff --git a/package.json b/package.json index 95ddc0d..3529170 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "@astrojs/solid-js": "^5.0.4", "@astrojs/tailwind": "^5.1.5", "astro": "^5.1.8", - "nodemailer": "^6.9.16", "solid-js": "^1.9.4", "tailwindcss": "^3.0.24" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a1340b6..80c2fef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,6 @@ importers: astro: specifier: ^5.1.8 version: 5.1.8(jiti@1.21.7)(rollup@4.31.0)(typescript@5.7.3)(yaml@2.7.0) - nodemailer: - specifier: ^6.9.16 - version: 6.9.16 solid-js: specifier: ^1.9.4 version: 1.9.4 @@ -1403,10 +1400,6 @@ packages: node-releases@2.0.19: resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==} - nodemailer@6.9.16: - resolution: {integrity: sha512-psAuZdTIRN08HKVd/E8ObdV6NO7NTBY3KsC30F7M4H1OnmLCUNaS56FpYxyb26zWLSyYF9Ozch9KYHhHegsiOQ==} - engines: {node: '>=6.0.0'} - normalize-path@3.0.0: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} @@ -3672,8 +3665,6 @@ snapshots: node-releases@2.0.19: {} - nodemailer@6.9.16: {} - normalize-path@3.0.0: {} normalize-range@0.1.2: {} diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx index 86a9756..5cbab0a 100644 --- a/src/components/ContactForm.tsx +++ b/src/components/ContactForm.tsx @@ -4,6 +4,7 @@ import { Show } from "solid-js/web"; const ContactForm: Component = () => { const [email, setEmail] = createSignal(""); const [message, setMessage] = createSignal(""); + const [name, setName] = createSignal(""); const [status, setStatus] = createSignal< "idle" | "sending" | "success" | "error" >("idle"); @@ -17,35 +18,51 @@ const ContactForm: Component = () => { try { const response = await fetch("/api/contact", { method: "POST", - headers: { - "Content-Type": "application/json", - }, + headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - email: email(), - message: message(), + subject: `New Contact Form Message from ${name()}`, + message: `From: ${name()}\nEmail: ${email()}\n\nMessage:\n${message()}`, }), }); + const data = await response.json(); + if (!response.ok) { - throw new Error("Failed to send message"); + throw new Error(data.error || data.message || "Failed to send message"); } setStatus("success"); + setName(""); setEmail(""); setMessage(""); - - // Reset success status after 3 seconds setTimeout(() => setStatus("idle"), 3000); } catch (error) { setStatus("error"); setErrorMessage( error instanceof Error ? error.message : "Failed to send message", ); + console.error("Submission error:", error); } }; return (
+
+ + setName(e.currentTarget.value)} + disabled={status() === "sending"} + /> +
+