Add job queue; e-mail sending; password reset support
This commit is contained in:
27
app/jobs/EMail.job.js
Normal file
27
app/jobs/EMail.job.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user