I am just getting this error message: Failed to send email: data is not defined.
...What I am trying to do is to implement resend library into my project. I've made an email template, it is working as intended, form submission is working too, but when I come to this part... I am just getting this error.
/** @format */
import { NextResponse } from "next/server";
import { Resend } from "resend";
import EmailTemplateWelcome from "@/app/emails/EmailTemplateWelcome";
const resend = new Resend(process.env.RESEND_API_KEY);
export async function POST(request, response) {
try {
const body = await request.json();
console.log("body", body);
const {
firstName,
lastName,
} = body;
console.log("firstName: ", firstName);
const data = await resend.emails.send({
from: "[email protected]",
to: "[email protected]",
subject: "Getting The Error",
react: EmailTemplateWelcome({
firstName,
lastName,
}),
});
return NextResponse.json(data);
} catch (error) {
if (error instanceof Error) {
console.log(`Failed to send email: ${error.message}`);
}
return NextResponse.json(
{
error: "Internal server error.",
},
{
status: 500,
}
);
}
}