HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //var/www/javago_test/src/helper/email.js
import nodemailer from "nodemailer";
import ejs from "ejs";

export async function sendMail(to, subject, html, OTP, type = 0) {
  let transporter = nodemailer.createTransport({
    host: "email-smtp.eu-west-2.amazonaws.com",
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: "AKIAQYECY2V3TLUJRRN7", // generated ethereal user
      pass: "BHnnsOAIz14rkESX4IKXGd9Dnf6nr/rLUVjtKMwsIqeF", // generated ethereal password
    },
  });
  console.log(transporter);
  try {
    let info = await transporter.sendMail({
      from: "no-reply@javaapp.co.uk", // sender address
      to: to, // list of receivers
      subject: subject, // Subject line
      html: html, // html body
    });
    return OTP;
  } catch (error) {
    console.log(error);
    return false;
  }
}

export async function sendVerifyOTPMail(email) {
  let data = {};
  data.otp = Math.floor(1000 + Math.random() * 9000);
  let options = {};
  let subject = "Java Go - OTP Verification";
  let html = await ejs.renderFile('./views/verify_otp.ejs', {
    data: data
  }, options)
  await sendMail(email, subject, html, data.otp);
  return data.otp;
}

export async function sendResetPasswordMail(name, email, token, user_type) {
  let data = {};
  data.name = name;
  data.password_reset_link = process.env.RESET_PASSWORD_LINK;
  let options = {};
  let html = await ejs.renderFile('./views/forgotten_password.ejs', {
    data: data
  }, options)
  let subject = "Java Go - Password Reset Request";
  await sendMail(email, subject, html, token, user_type);
  return token;
}

export async function sendCafeRequestMail(email, cafe_name, password) {
  let data = {
    email: email,
    cafe_name: cafe_name,
    password: password,
    link: process.env.CAFE_PANEL_LOGIN_LINK
  };
  let options = {};
  let subject = "Welcome to Java Go";
  let html = await ejs.renderFile('./views/request_cafe.ejs', {
    data: data
  }, options)
  await sendMail(email, subject, html);
  return data.otp;
}