const { Job } = require('flitter-jobs') class EMailJob extends Job { static get services() { return [...super.services, 'smtp', 'output', 'configs'] } async execute(job) { try { const config = this.smtp.config() const transport = this.smtp.transport() const { data } = job let { from = config.default_sender, to, subject, html = undefined, email_params = undefined } = data this.output.info(`Sending mail to ${to}...`) if ( !html && email_params ) html = this.email(email_params) await transport.sendMail({ from, to, subject, html, }) } catch (e) { this.output.error(e) } this.output.success(`Mail sent!`) } email({ header_text, body_paragraphs = [], button_text = '', button_link = '' }) { const app_name = this.configs.get('app.name') const login_url = this.configs.get('app.url') + 'auth/login' // Build the body paragraphs const body_text = body_paragraphs.map(x => { return `

${x}

` }).join(`

`) let button_html = '' if ( button_text && button_link ) { button_html = `
${button_text}
` } return ` ` } } module.exports = exports = EMailJob