"use server"
import nodemailer from "nodemailer";
import Mail from "nodemailer/lib/mailer";
import SMTPTransport from "nodemailer/lib/smtp-transport";

const transport = nodemailer.createTransport({
    host: process.env.MAIL_HOST,
    port: process.env.MAIL_PORT,
    // secure: process.env.NODE_ENV !== 'development', //true // DO NOT USE FOR PRODUCTION BUILD
    auth: {
        user: process.env.MAIL_USER,
        pass: process.env.MAIL_PASSWORD
    },
} as SMTPTransport.Options)

type SendEmailDto = {
    sender: Mail.Address,
    recipients: Mail.Address[],
    subject: string;
    message: string;
    // react: React.ReactNode;
}
export const sendEmails = async (dto: SendEmailDto) => {
    const { sender, recipients, subject, message} = dto;

    return await transport.sendMail({
        from: sender,
        to: recipients,
        subject: subject,
        html: message,
        text: message,
        // react: react,
    })
}