You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CoreID/app/jobs/EMail.job.js

28 lines
691 B

const { Job } = require('flitter-jobs')
class EMailJob extends Job {
static get services() {
return [...super.services, 'smtp', 'output']
}
async execute(job) {
const config = this.smtp.config()
const transport = this.smtp.transport()
const { data } = job
const { from = config.default_sender, to, subject, html } = data
this.output.info(`Sending mail to ${to}...`)
try {
await transport.sendMail({
from, to, subject, html,
})
} catch (e) {
this.output.error(e)
}
this.output.success(`Mail sent!`)
}
}
module.exports = exports = EMailJob