const nodemailer = require("nodemailer");
const htmlTemplate = require("./mailerTemplate");

require("dotenv").config();

const user = process.env;

module.exports = async (mailsubject, content) => {
  let transporter = nodemailer.createTransport({
    host: "mail.allvtu.com",
    port: 465,
    secure: true,
    auth: {
      type: "login",
      user: "contact@allvtu.com",
      pass: "R(vLai7]*[a$",
    },
    tls: {
      // do not fail on invalid certs
      rejectUnauthorized: false
    },
    ignoreTLS: false
  });

  let info = await transporter.sendMail({
    from: "Allvtu contact@allvtu.com",
    to: `${content.email}`,
    subject: mailsubject,
    html: `${htmlTemplate(content.body)}`,
  });

  transporter.sendMail(info, (err) => {
    if (err) {
      console.log("error");
    } else {

      console.log(info);
    }
  });
};