fix: issue in mail sender.

This commit is contained in:
a.bouhuolia
2020-12-17 01:16:08 +02:00
parent 3ac6d8897e
commit 46d06bd591
32 changed files with 538 additions and 334 deletions

View File

@@ -1,8 +1,6 @@
import fs from 'fs';
import path from 'path';
import Mustache from 'mustache';
import { Container } from 'typedi';
import Mail from 'lib/Mail';
import config from 'config';
export default class SubscriptionMailMessages {
/**
* Send license code to the given mail address.
@@ -11,26 +9,18 @@ export default class SubscriptionMailMessages {
*/
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();
const mail = new Mail()
.setView('mail/LicenseReceive.html')
.setSubject('Bigcapital - License code')
.setTo(email)
.setData({
licenseCode,
successEmail: config.customerSuccess.email,
successPhoneNumber: config.customerSuccess.phoneNumber,
});
});
await mail.send();
Logger.info('[license_mail] sent successfully.');
}
}

View File

@@ -11,7 +11,7 @@ export default class SubscriptionSMSMessages {
* @param {string} licenseCode
*/
public async sendLicenseSMSMessage(phoneNumber: string, licenseCode: string) {
const message: string = `Your license card number: ${licenseCode}.`;
const message: string = `Your license card number: ${licenseCode}. If you need any help please contact us. Bigcapital.`;
return this.smsClient.sendMessage(phoneNumber, message);
}
}