Files
bigcapital/server/src/services/Payment/LicenseMailMessages.ts
Ahmed Bouhuolia a22c8395f3 feat: remove path alias.
feat: remove Webpack and depend on nodemon.
feat: refactoring expenses.
feat: optimize system users with caching.
feat: architecture tenant optimize.
2020-09-15 00:51:39 +02:00

36 lines
1.0 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import Mustache from 'mustache';
import { Container } from 'typedi';
export default class SubscriptionMailMessages {
/**
* Send license code to the given mail address.
* @param {string} licenseCode
* @param {email} email
*/
public async sendMailLicense(licenseCode: string, email: string) {
const Logger = Container.get('logger');
const Mail = Container.get('mail');
const filePath = path.join(global.__root, 'views/mail/LicenseReceive.html');
const template = fs.readFileSync(filePath, 'utf8');
const rendered = Mustache.render(template, { licenseCode });
const mailOptions = {
to: email,
from: `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`,
subject: 'Bigcapital License',
html: rendered,
};
return new Promise((resolve, reject) => {
Mail.sendMail(mailOptions, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
}
}