"use server"; import nodemailer from "nodemailer"; export type ContactPayload = { name: string; email: string; company: string; phone: string; topic: string; message: string; }; export type SendResult = { ok: true } | { ok: false; error: string }; export async function sendContactEmail(data: ContactPayload): Promise { const { SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS } = process.env; if (!SMTP_HOST || !SMTP_USER || !SMTP_PASS) { return { ok: false, error: "Konfigurasi email server belum diatur." }; } const transporter = nodemailer.createTransport({ host: SMTP_HOST, port: Number(SMTP_PORT ?? 587), secure: Number(SMTP_PORT) === 465, auth: { user: SMTP_USER, pass: SMTP_PASS }, }); const html = `

Pesan Baru dari Website IPTEK

Nama${data.name}
Email${data.email}
Perusahaan${data.company || "-"}
WhatsApp${data.phone || "-"}
Topik${data.topic}

Pesan

${data.message}

Dikirim pada ${new Date().toLocaleString("id-ID", { timeZone: "Asia/Jakarta", dateStyle: "long", timeStyle: "short" })} WIB
`; try { await transporter.sendMail({ from: `"IPTEK Website" <${SMTP_USER}>`, to: "support@iptek.co", replyTo: data.email, subject: `[${data.topic}] Pesan dari ${data.name} – IPTEK Website`, html, }); return { ok: true }; } catch (err) { console.error("Email send error:", err); return { ok: false, error: "Gagal mengirim pesan. Silakan coba lagi atau hubungi kami langsung." }; } }