import nodemailer from 'nodemailer';

export async function sendEmail(p0: { to: string; subject: string; html: string; }) {
  const { to, subject, html } = p0;
  if (!to || !subject || !html) {
    throw new Error('Missing required email parameters: to, subject, or html');
  }
  const transporter = nodemailer.createTransport({
    host: 'mail.banksfinders.com', // ✅ important
    port: 465,                     // or 587 if using secure: false
    secure: true,                  // SSL/TLS
    auth: {
      user: 'no-reply@banksfinders.com',
      pass: process.env.EMAIL_PASS || 'H&4wm=l[4l!+',
    },
    tls: {
      rejectUnauthorized: false, // useful for shared hosting certs
    },
    logger: true,
    debug: true,
  });

  const info = await transporter.sendMail({
    from: 'no-reply@banksfinders.com', // sender address
    to :'apply@banksfinders.com' , // list of receivers
    // to: '
    cc: to, // CC address
    subject,
    html,
  });

  console.log('Message sent: %s', info.messageId);
}
