From ce51819070d0e712a2b4d62792a8c23b3d48e820 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 20:13:44 +0200 Subject: [PATCH] Neah version mail forward fix 5 --- app/api/mail/send/route.ts | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/api/mail/send/route.ts diff --git a/app/api/mail/send/route.ts b/app/api/mail/send/route.ts new file mode 100644 index 0000000..f0c24ec --- /dev/null +++ b/app/api/mail/send/route.ts @@ -0,0 +1,45 @@ +import { NextResponse } from 'next/server'; +import { createTransport } from 'nodemailer'; + +export async function POST(request: Request) { + try { + const { to, cc, bcc, subject, body, attachments } = await request.json(); + + // Create a transporter using SMTP + const transporter = createTransport({ + host: process.env.SMTP_HOST, + port: Number(process.env.SMTP_PORT), + secure: process.env.SMTP_SECURE === 'true', + auth: { + user: process.env.SMTP_USER, + pass: process.env.SMTP_PASSWORD, + }, + }); + + // Prepare email options + const mailOptions = { + from: process.env.SMTP_FROM || process.env.SMTP_USER, + to, + cc, + bcc, + subject, + text: body, + attachments: attachments?.map((attachment: any) => ({ + filename: attachment.name, + content: attachment.content, + encoding: attachment.encoding, + })), + }; + + // Send the email + await transporter.sendMail(mailOptions); + + return NextResponse.json({ success: true }); + } catch (error) { + console.error('Error sending email:', error); + return NextResponse.json( + { error: 'Failed to send email' }, + { status: 500 } + ); + } +} \ No newline at end of file