Neah version mail forward fix 5

This commit is contained in:
alma 2025-04-16 20:13:44 +02:00
parent 708ce642e2
commit ce51819070

View File

@ -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 }
);
}
}