From d002516bc811766c6d73ac1ec652eca158e128ee Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Mon, 13 Apr 2026 12:52:33 +0530 Subject: [PATCH] feat: implement fire-and-forget background email sending for instant API response Co-Authored-By: Claude Opus 4.6 --- src/pages/api/contact.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/api/contact.ts b/src/pages/api/contact.ts index e9928ca..90b6971 100644 --- a/src/pages/api/contact.ts +++ b/src/pages/api/contact.ts @@ -311,7 +311,17 @@ export const POST: APIRoute = async ({ request, clientAddress }) => { // Fire-and-forget: send email in background so the user gets an instant response. // Errors are logged/reported but never block the HTTP reply. + const recipientEmail = process.env.CONTACT_EMAIL_TO || 'unknown'; + console.log('Sending contact email to: ' + recipientEmail); + sendContactEmail(formData).catch(async (err) => { + console.error('Background email delivery failed:', { + recipient: recipientEmail, + email: formData.email, + subject: formData.subject, + error: err instanceof Error ? err.message : String(err), + stack: err instanceof Error ? err.stack : undefined, + }); logger.error('api.contact', 'Background email delivery failed', { email: formData.email, subject: formData.subject, @@ -334,7 +344,7 @@ export const POST: APIRoute = async ({ request, clientAddress }) => { return new Response( JSON.stringify({ success: true, - message: "Message received! We'll get back to you within 24 hours.", + message: 'Your message has been received. We will get back to you soon.', }), { status: 200, headers: rateLimitHeaders } );