"use client"; import Link from "next/link" import { emailSchema } from "@/lib/email/utils"; import { useRef, useState } from "react"; import { z } from "zod"; type FormInput = z.infer; type Errors = { [K in keyof FormInput]: string[] }; export default function Home() { const [sending, setSending] = useState(false); const [errors, setErrors] = useState(null); const nameInputRef = useRef(null); const emailInputRef = useRef(null); const sendEmail = async () => { setSending(true); setErrors(null); try { const payload = emailSchema.parse({ name: nameInputRef.current?.value, email: emailInputRef.current?.value, }); console.log(payload); const req = await fetch("/api/email", { method: "POST", body: JSON.stringify(payload), headers: { "Content-Type": "application/json", }, }); const { id } = await req.json(); if (id) alert("Successfully sent!"); } catch (err) { if (err instanceof z.ZodError) { setErrors(err.flatten().fieldErrors as Errors); } } finally { setSending(false); } }; return (

Send Email with Resend

  1. Sign up {" "} or{" "} Login {" "} to your Resend account
  2. Add and verify your domain
  3. Create an API Key and add to{" "} .env
  4. Update "from:" in{" "} app/api/email/route.ts
  5. Send email 🎉
e.preventDefault()} className="space-y-3 pt-4 border-t mt-4" > {errors && (

{JSON.stringify(errors, null, 2)}

)}
); }