Neah version mail forward fix 5
This commit is contained in:
parent
708ce642e2
commit
ce51819070
45
app/api/mail/send/route.ts
Normal file
45
app/api/mail/send/route.ts
Normal 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user