Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async send({ req, response }) {
let data = Buffer.from(req.data)
data = JSON.parse(data.toString())
const email = new Email({
message: {
from: 'akzdinglasan@gmail.com' // change to support email later
},
send: true,
transport: this._transporter
})
this._logger.info(`${this._serviceName}#send.call`, req)
try {
const result = await email.send({
template: path.join(__dirname, '../', 'templates', req.template),
message: {
to: req.to
},
locals: {
const send = async (templateName, subscription, vars, from, transporter) => {
// email template object. use passed variables or from env conf
const emailTpl = new EmailTemplate({
message: {
from: from || conf.email.SYSTEM_EMAIL_FROM_ADDRESS
},
send: true,
transport: transporter || getDefaultTransporter(),
views: {
root: path.resolve('src/email_templates'),
options: {
extension: 'ejs'
}
}
});
// prepare template vars
const templateVars = Object.assign(_cloneDeep(vars || {}), {
template: templateName,
secure: configLoader.loadBoolConfig('MAIL_SSL'), // upgrade later with STARTTLS
auth: {
user: configLoader.loadConfig('MAIL_USERNAME'),
pass: configLoader.loadConfig('MAIL_PASSWORD'),
},
};
this.transporter = mailer.createTransport(transport);
} else {
logger.warn(oneLine`
MAIL_HOST && MAIL_PORT && MAIL_USERNAME && MAIL_PASSWORD
must be set up to send mail in real world
`);
this.transporter = mailer.createTransport({ jsonTransport: true });
}
this.emailTemplate = new EmailTemplate({
message: {
from: configLoader.loadConfig('MAIL_FROM') || configLoader.loadConfig('MAIL_USERNAME'),
},
preview: false,
send: true, // will send emails in development/test env
subjectPrefix: env === 'production' ? false : `[${env.toUpperCase()}] `,
transport: this.transporter,
});
}
import i18n from 'i18n'
import Email from 'email-templates'
const Mailer = new Email({
message: {
from: process.env.MAIL_FROM
},
send: true,
transport: {
host: process.env.MAIL_HOST,
port: Number(process.env.MAIL_PORT),
auth: {
user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD,
},
i18n: i18n.__,
}
})
export default Mailer