-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathworker.ts
More file actions
35 lines (31 loc) · 810 Bytes
/
worker.ts
File metadata and controls
35 lines (31 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Worker } from "bullmq";
import nodemailer from "nodemailer";
import redis from "../redis";
import { logger } from "../logger";
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
port: +(process.env.EMAIL_PORT || 587),
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
const worker = new Worker(
"mail",
async (job) => {
const { to, from, subject, body, headers } = job.data;
try {
await transporter.sendMail({
from,
to,
subject,
html: body,
headers,
});
} catch (err: any) {
logger.error(err);
}
},
{ connection: redis },
);
export default worker;