102 lines
5.0 KiB
JavaScript
102 lines
5.0 KiB
JavaScript
import nodemailer from "nodemailer";
|
|
|
|
export const offerLetter = async (req, res)=>{
|
|
/*
|
|
loan": {
|
|
"id": "47",
|
|
"uid": "18352568-df88-462c-bcc2-22f075a61b93",
|
|
"customer_uid": "0d7f3c0a-0242-4b7e-9e45-26e28d436473",
|
|
"loan_amount": "400000",
|
|
"payment_month": "12",
|
|
"sales_agent": "2442552",
|
|
"gender": null,
|
|
"marital_status": "single",
|
|
"email": "oladeji@gmail.com",
|
|
"address": "3235 SATELLITE BLVD STE 300",
|
|
"state": "lagos",
|
|
"country": "NG",
|
|
"loan_detail": "{\"customer_uid\":\"0d7f3c0a-0242-4b7e-9e45-26e28d436473\",\"loan_amount\":\"400000\",\"payment_month\":\"12\",\"sales_agent\":\"2442552\",\"gender\":\"male\",\"address\":\"3235 SATELLITE BLVD STE 300\",\"marital_status\":\"single\",\"state\":\"lagos\",\"email\":\"oladeji@gmail.com\",\"country\":\"NG\",\"employer_uid\":\"b44a3f7e-ee55-4dbe-9f71-1329f287147e\",\"employment\":\"{\\\"job_title\\\":\\\"Engineer\\\",\\\"name\\\":\\\"\\\",\\\"sector\\\":\\\"\\\",\\\"industry\\\":\\\"\\\",\\\"resumption_date\\\":\\\"2024-12-26\\\",\\\"email\\\":\\\"\\\",\\\"annual_income\\\":\\\"2000000\\\",\\\"monthly_salary\\\":\\\"400000\\\",\\\"salary_payment_date\\\":\\\"2025-01-06\\\",\\\"employment_id\\\":\\\"12345678\\\",\\\"highest_eductaion\\\":\\\"b.sc + professional qualification\\\",\\\"isChecked\\\":false}\",\"loan_reference\":\"[{\\\"fullname\\\":\\\"BJ ola\\\",\\\"relationship\\\":\\\"Friend\\\",\\\"phone_number\\\":\\\"4042722172\\\",\\\"email\\\":\\\"bjnett@gmail.com\\\",\\\"bvn\\\":\\\"12345676543\\\"},{\\\"fullname\\\":\\\"ADe Bola\\\",\\\"relationship\\\":\\\"Sister\\\",\\\"phone_number\\\":\\\"4042722173\\\",\\\"email\\\":\\\"oladeji@gmail.com\\\",\\\"bvn\\\":\\\"53573663777\\\"}]\",\"disbursement_account\":\"0210501965\",\"disbursement\":\"{\\\"account\\\":\\\"0210501965\\\"}\"}",
|
|
"status": "4",
|
|
"added": "2025-01-12 22:07:33.735895",
|
|
"updated": "2025-01-12 22:07:33.735895",
|
|
"employer_uid": "b44a3f7e-ee55-4dbe-9f71-1329f287147e",
|
|
"disbursement_account": "0210501965",
|
|
"pc": "0"
|
|
},
|
|
*/
|
|
|
|
|
|
try {
|
|
console.log("verifyEmployer REQ-----------------------------------------");
|
|
console.log(req.body);
|
|
console.log("verifyEmployer REQ=========================================");
|
|
|
|
const employee_name = req.body.firstname; // "EMPLOYEE NAME";
|
|
const signatory_name = req.body.signatory_name;
|
|
const loan_amount = req.body.loan_amount;
|
|
const payment_month = req.body.payment_month; //"1234567890";
|
|
const application_uid = req.body.application_uid;
|
|
const target_email = req.body.email;
|
|
|
|
const mainHtml = `
|
|
Dear, ${employee_name},
|
|
|
|
We are happy to present your loan offer with the details below: \n
|
|
|
|
Loan Offer \n
|
|
Loan Amount: N ${loan_amount}
|
|
Tenor: ${payment_month} months
|
|
Monthly Interest rate: 5%
|
|
Management Fee (taken upfront): 1%
|
|
Insurance fee (taken upfront): 1%
|
|
Installment payment: N112,825.41
|
|
Next repayment date: February 12, 2025
|
|
Total repayment: N1,353,904.92 \n
|
|
Accept Loan Offer \n\n
|
|
|
|
***Loan Offer Approval (You are to login with this to your portal to approve the loan) \n\n
|
|
|
|
If you have any questions or concerns about this email, please get in touch with our finance department at processingbank@email.com. \n\n
|
|
|
|
Kind Regards,\n
|
|
|
|
Finance team,\n
|
|
Processing Bank\n
|
|
`;
|
|
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
service: "gmail",
|
|
host: "smtp.gmail.com",
|
|
port: 587,
|
|
secure: false,
|
|
auth: {
|
|
user: "message@chiefsoft.com",
|
|
pass: "may12002!",
|
|
},
|
|
});
|
|
// async..await is not allowed in global scope, must use a wrapper
|
|
async function main() {
|
|
// send mail with defined transport object
|
|
const info = await transporter.sendMail({
|
|
from: '"Support ChiefSoft 👻" <message@chiefsoft.com>', // sender address
|
|
to: target_email, // list of receivers
|
|
bcc: "ameye@chiefsoft.com, victor.ebuka@chiefsoft.com", // list of receivers
|
|
subject: "Bank Loan Offer ✔", // Subject line
|
|
text: "Hello "+signatory_name+"?", // plain text body
|
|
html: mainHtml, // html body
|
|
});
|
|
console.log("Message sent: %s", info.messageId);
|
|
// Message sent: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>
|
|
}
|
|
main().catch(console.error);
|
|
|
|
return res.json({res : 'sent'});
|
|
|
|
}
|
|
catch(error){
|
|
res.status(500).json({error: "Internal Server error"});
|
|
}
|
|
|
|
|
|
} |