const nodemailer = require('nodemailer');

// Create a Nodemailer transporter using your email service credentials
const transporter = nodemailer.createTransport({
  service: 'https://buildmart.ph',
  auth: {
    user: 'mail@buildmart.ph', // Replace with your email
    pass: '~g?fjnAvk5sl',  // Replace with your email password or an app-specific password
  },
});

// Function to send an email
const sendEmail = async (to, subject, text) => {
  try {
    // Setup email data
    const mailOptions = {
      from: 'mail@buildmart.ph', // Replace with your email
      to,
      subject,
      text,
    };

    // Send the email
    const info = await transporter.sendMail(mailOptions);
    console.log('Email sent:', info.response);
  } catch (error) {
    console.error('Error sending email:', error);
  }
};

module.exports = sendEmail;
