I'm trying to send a transactional mail with resend.
It works great locally, but on live i cant even seem to trigger my api route.
Those console.log I've put in there, dont even trigger on my vercel deployment but they work great on local dev and build environment
I hope someone can help me out here
This is my app/api/resend/route.ts
import { NextRequest } from 'next/server';
export const dynamic = 'force-dynamic';
const resendAPIKey = process.env.RESEND_API_KEY;
if (!resendAPIKey) {
throw new Error('RESEND_API_KEY is not defined');
}
export async function POST(req: NextRequest) {
const { email, beat } = await req.json();
console.log('Sending email to', email);
const res = await fetch('https://api.resend.com/emails', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${resendAPIKey}`
},
body: JSON.stringify({
from: '[email protected]',
to: `${email}`,
subject: 'Dein Demo Download ist da! 🎉',
attachments: [
{
filename: beat.name,
path: beat.url
}
],
html: `
<h1>Dein Demo Download ist da! 🎉</h1>
<p>Hey, du hast dir gerade einen Demo Download von CatchBeatz gesichert! 🎉</p>
<p>Dein Download: <a href="${beat.url}">${beat.name}</a></p>
<p>Ich hoffe, dass dir der Beat gefällt! 🎵</p>
<p>Wenn du Fragen hast, schreib mir einfach eine E-Mail an <a href="mailto:xxx">
`
})
});
const data = await res.json();
console.log('Email sent', data);
if (res.ok) {
return Response.json(data);
}
}