-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.js
38 lines (32 loc) · 1.08 KB
/
mailer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const moment = require('moment');
const nodemailer = require('nodemailer');
const logger = require('./logger');
const { getEmailTemplate } = require('./business');
const { AUBIT_FROM_EMAIL, AUBIT_FROM_EMAIL_PASSWORD } = process.env;
/**
*
* @param {{to, bcc, cc, subject, text, attachments}} config Email basic configuration
* @param {{templateId, data}} templateConfiguration Template information needs to fill up in the email
*/
exports.sendEmail = async (config, templateConfiguration) => {
const emailConfiguration = {
...config,
from: AUBIT_FROM_EMAIL,
html: await getEmailTemplate(templateConfiguration)
};
/**
* Note: This transport creation from email should be enabled third party devices login
* and enable Less secure app block on gmail settings.
*/
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: AUBIT_FROM_EMAIL,
pass: AUBIT_FROM_EMAIL_PASSWORD
}
});
transporter.sendMail(emailConfiguration, function (err) {
if (err) return logger.error(err);
logger.info(`Email sent at ${moment().format('LLLL')}.`);
});
};