Neah/app/api/parse-email/route.ts
2025-04-24 19:43:23 +02:00

29 lines
759 B
TypeScript

import { NextResponse } from 'next/server';
import { simpleParser } from 'mailparser';
export async function POST(request: Request) {
try {
const body = await request.json();
const { emailContent } = body;
if (!emailContent || typeof emailContent !== 'string') {
return NextResponse.json(
{ error: 'Invalid email content' },
{ status: 400 }
);
}
const parsed = await simpleParser(emailContent);
return NextResponse.json({
html: parsed.html || null,
text: parsed.textAsHtml || parsed.text || null
});
} catch (error) {
console.error('Error parsing email:', error);
return NextResponse.json(
{ error: 'Failed to parse email' },
{ status: 500 }
);
}
}