From 7109b3c32e8fe1769f1ccd1e9b6e211d20185ffc Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 14 Apr 2026 22:28:45 +0200 Subject: [PATCH] fix: add detailed smtp logging to debug confirmation email --- app/api/contact/route.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/api/contact/route.ts b/app/api/contact/route.ts index 982a175..c4455ab 100644 --- a/app/api/contact/route.ts +++ b/app/api/contact/route.ts @@ -115,16 +115,23 @@ export async function POST(req: Request) { }), ); - await transporter.sendMail({ - from: config.mail.from, - to, - replyTo: email, - subject: `Kontaktanfrage von ${name}`, - html: notificationHtml, - }); + try { + const info = await transporter.sendMail({ + from: config.mail.from, + to, + replyTo: email, + subject: `Kontaktanfrage von ${name}`, + html: notificationHtml, + }); + logger.info("Notification email sent successfully", { messageId: info.messageId }); + } catch (notifyError) { + logger.error("Failed to send notification email", { error: notifyError }); + throw notifyError; // Re-throw to be caught by the outer SMTP catch + } // 2b. Confirmation to the User try { + logger.info("Preparing to send confirmation email", { to: email }); const confirmationHtml = await render( React.createElement(ConfirmationMessage, { name, @@ -132,16 +139,17 @@ export async function POST(req: Request) { }), ); - await transporter.sendMail({ + const info = await transporter.sendMail({ from: config.mail.from, to: email, subject: `Ihre Kontaktanfrage bei ${clientName}`, html: confirmationHtml, }); + logger.info("Confirmation email sent successfully", { messageId: info.messageId }); } catch (confirmError) { logger.warn( "Failed to send confirmation email, but notification was sent", - { error: confirmError }, + { error: confirmError instanceof Error ? confirmError.message : String(confirmError) }, ); }