import nodemailer from "nodemailer";

// Configuration du transporteur (À remplir avec vos accès SMTP)
const transporter = nodemailer.createTransport({
    host: process.env.SMTP_HOST || "smtp.example.com",
    port: parseInt(process.env.SMTP_PORT || "587"),
    secure: process.env.SMTP_SECURE === "true", // true for 465, false for other ports
    auth: {
        user: process.env.SMTP_USER || "user@example.com",
        pass: process.env.SMTP_PASS || "password",
    },
});

export async function sendNotificationEmail(subject: string, html: string) {
    try {
        const info = await transporter.sendMail({
            from: `"Projet Portfolio" <${process.env.SMTP_USER || "noreply@example.com"}>`,
            to: process.env.ADMIN_EMAIL || "admin@example.com",
            subject: subject,
            html: html,
        });
        console.log("Email envoyé: %s", info.messageId);
        return true;
    } catch (error) {
        console.error("Erreur d'envoi d'email:", error);
        return false;
    }
}
