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.info(`Sending mail to ${to}...`) if ( !html && email_params ) html = this.email(email_params) await transport.sendMail({ from, to, subject, html, }) } catch (e) { this.error(e) throw e } this.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}
`) let button_html = '' if ( button_text && button_link ) { button_html = `
${app_name}
${header_text}
${body_text}
${app_name} | Login |