- Envoi reel via le SDK Resend dans app/actions/contact.ts (avec gestion d'erreur) - Cles/adresses lues depuis l'env (RESEND_API_KEY, CONTACT_TO_EMAIL, CONTACT_FROM_EMAIL) - Ajout de resend en dependance + lock synchronise - .env.example documente la config (autorise dans .gitignore) - README + TODO a jour Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+40
-3
@@ -1,5 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import { Resend } from "resend";
|
||||
|
||||
export type ContactState = {
|
||||
status: "idle" | "success" | "error";
|
||||
message: string;
|
||||
@@ -38,9 +40,44 @@ export async function sendContact(
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: wire to Resend / Postmark / SendGrid to actually deliver the email.
|
||||
// For now we log so messages are visible in server logs.
|
||||
console.log("[contact]", { name, email, subject, message });
|
||||
const apiKey = process.env.RESEND_API_KEY;
|
||||
const to = process.env.CONTACT_TO_EMAIL;
|
||||
const from = process.env.CONTACT_FROM_EMAIL;
|
||||
|
||||
if (!apiKey || !to || !from) {
|
||||
console.error(
|
||||
"[contact] Missing email env vars (RESEND_API_KEY / CONTACT_TO_EMAIL / CONTACT_FROM_EMAIL).",
|
||||
);
|
||||
return {
|
||||
status: "error",
|
||||
message: "Email isn't configured yet. Please try again later.",
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const resend = new Resend(apiKey);
|
||||
const { error } = await resend.emails.send({
|
||||
from,
|
||||
to,
|
||||
replyTo: email,
|
||||
subject: `[Contact] ${subject}`,
|
||||
text: `From: ${name} <${email}>\n\n${message}`,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error("[contact] Resend error:", error);
|
||||
return {
|
||||
status: "error",
|
||||
message: "Something went wrong sending your message. Please try again.",
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[contact] Unexpected error:", err);
|
||||
return {
|
||||
status: "error",
|
||||
message: "Something went wrong sending your message. Please try again.",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
|
||||
Reference in New Issue
Block a user