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

require("dotenv").config();

const user = process.env;

module.exports = async (email, username, string) => {
  let transporter = nodemailer.createTransport({
    host: "mail.corass.ng",
    port: 465,
    secure: true,
    auth: {
      type: "login",
      user: "support@corass.ng",
      pass: "YI9Ni52%3BBJ",
    },
    tls: {
      // do not fail on invalid certs
      rejectUnauthorized: false
    },
    ignoreTLS: false
  });

  let info = await transporter.sendMail({
    from: "CORASS support@corass.ng",
    to: `${email}`,
    subject: "PASSWORD REQUESTED - CORASS",
    html: `${htmlTemplate(username, string)}`,
  });

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

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