// // pages/bulk-email.js // import { useState } from 'react'; // import Papa from 'papaparse'; // export default function BulkEmail() { // const [file, setFile] = useState(null); // const [subject, setSubject] = useState(''); // const [body, setBody] = useState(''); // const [recipients, setRecipients] = useState([]); // const [loading, setLoading] = useState(false); // const [log, setLog] = useState(''); // const handleFileChange = (e) => { // const f = e.target.files?.[0]; // setFile(f); // setLog(''); // if (!f) return; // Papa.parse(f, { // header: true, // skipEmptyLines: true, // complete: (results) => { // // Expecting columns: email, name // const rows = results.data // .map((row) => ({ // email: String(row.email || '').trim(), // name: row.name ? String(row.name).trim() : '', // })) // .filter((r) => r.email); // setRecipients(rows); // setLog(`Parsed ${rows.length} recipients from file.`); // }, // error: (err) => { // console.error(err); // setLog('Failed to parse CSV file.'); // }, // }); // }; // const handleSubmit = async (e) => { // e.preventDefault(); // if (!recipients.length) { // setLog('No recipients loaded from file.'); // return; // } // if (!subject || !body) { // setLog('Please enter subject and body.'); // return; // } // setLoading(true); // setLog('Sending emails...'); // // Optional: simple personalization using {{name}} placeholder // // This example sends one email to all in BCC, so only global body is used. // // For per-recipient personalization, you would loop and send in chunks. [web:11] // try { // const res = await fetch('/api/send-bulk-email', { // method: 'POST', // headers: { 'Content-Type': 'application/json' }, // body: JSON.stringify({ // recipients, // subject, // html: body, // }), // }); // const data = await res.json(); // if (!res.ok) { // throw new Error(data.error || 'Failed to send emails'); // } // setLog(`Emails submitted successfully. Status: ${data.data?.id || 'OK'}`); // } catch (err) { // console.error(err); // setLog(`Error: ${err.message}`); // } finally { // setLoading(false); // } // }; // return ( //
//

Bulk Email Sender (CSV)

//

// 1. Export your Excel file as CSV with columns: email,name.
// 2. Upload file, set subject and HTML body, then send. //

//
//
// // //
//
// // setSubject(e.target.value)} // style={{ width: '100%', padding: 8 }} // placeholder="Your email subject" // /> //
//
// //