confirmation email to users #6686
Replies: 1 comment 1 reply
-
@harpyasatanara You could use a service like Resend to send off emails from your serverless functions and generate those emails either traditionally or through a tool like React Email to get it as clean and simple as import { EmailTemplate } from "@/components/EmailExample";
import { NextRequest, NextResponse } from "next/server";
import { Resend } from "resend";
const resend = new Resend(process.env.RESEND_API_KEY);
export async function POST(
request: NextRequest,
): Promise<NextResponse<string>> {
const {
name,
email,
}: { name: string | undefined; email: string | undefined } =
await request.json();
if (name === undefined || email === undefined) {
return NextResponse.json("Missing name or email", { status: 400 });
}
const { error } = await resend.emails.send({
from: "Acme <[email protected]>",
to: [email],
subject: "Hello world",
react: EmailTemplate({ firstName: name }),
});
if (error) {
return NextResponse.json(error as string, { status: 500 });
} else {
return NextResponse.json("Successfully sent", { status: 200 });
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
Could anyone tell me how I can send a confirmation email to users when they fill out a form on the website?
Beta Was this translation helpful? Give feedback.
All reactions