const mysql = require('mysql2');
const pool = require('../helpers/db').pool;
const nodemailer = require('nodemailer');
//const Property = require("../models/PropertyModel").Property;


// async..await is not allowed in global scope, must use a wrapper
async function main(from, to, subject, text) {

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
      host: "mail.24hrslocksmith.co.uk",
      port: 465,
      secure: true,
      auth: {
        user: "no-reply@24hrslocksmith.co.uk",
        pass: "t]{ZL]p8peL)",
      },
    });
  
    from = from ? from : 'no-reply@24hrslocksmith.co.uk'
    to = to ? to : ''
    email = email ? email : 'tech@digital-interaction.com'
    phone = phone ? phone : '0722659559'
    message = message ? message : 'Test mssg'
    
    // // send mail with defined transport object
    // let info = await transporter.sendMail({
    //   from: '"24hrs Locksmith" <no-reply@24hrslocksmith.co.uk>', // sender address
    //   to: "tech@digitalinteraction.eu, postelnicuvlad4@gmail.com", // list of receivers
    //   subject: "Node test mail 1", // Subject line
    //   text: "Hello world?", // plain text body
    //   html: "<b>Hello world?</b>", // html body
    // }); 

    // send mail with defined transport object
    let info = await transporter.sendMail({
      from: '"${name}" <no-reply@24hrslocksmith.co.uk>', // sender address
      to: "tech@digitalinteraction.eu, postelnicuvlad4@gmail.com", // list of receivers
      subject: "Node test mail 1", // Subject line
      text: "Hello world?", // plain text body
      html: "<b>Hello world?</b>", // html body
    }); 
  
    console.log("Message sent: %s", info.messageId);
  }
  

const mail_send = (req, res) => {
    main().catch(console.error);
  }
  
module.exports = {
    mail_send,
  }