mail page imap connection mime 5 bis rest 16 login page 12

This commit is contained in:
alma 2025-04-16 00:09:12 +02:00
parent 6a5e1bcec6
commit 7e15a70def

View File

@ -176,4 +176,56 @@ export async function GET() {
{ status }
);
}
}
export async function POST(request: Request) {
try {
const credentials = getStoredCredentials();
if (!credentials) {
return NextResponse.json(
{ error: 'No stored credentials found' },
{ status: 401 }
);
}
const { to, subject, body, attachments } = await request.json();
if (!to || !subject || !body) {
return NextResponse.json(
{ error: 'Missing required fields' },
{ status: 400 }
);
}
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: credentials.host,
port: credentials.port,
secure: true,
auth: {
user: credentials.email,
pass: credentials.password,
},
});
const mailOptions = {
from: credentials.email,
to,
subject,
text: body,
attachments: attachments || [],
};
const info = await transporter.sendMail(mailOptions);
console.log('Email sent:', info.messageId);
return NextResponse.json({ success: true, messageId: info.messageId });
} catch (error) {
console.error('Error sending email:', error);
return NextResponse.json(
{ error: error instanceof Error ? error.message : 'Failed to send email' },
{ status: 500 }
);
}
}