+import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
import { smtpClientPool } from './pool.js'
const tos = ['bar@example.com, baz@example.com']
-const smtpClientPoolPromises = new Set<Promise<unknown>>()
+const smtpClientPoolPromises = new Set<Promise<SMTPTransport.SentMessageInfo>>()
for (const to of tos) {
smtpClientPoolPromises.add(
smtpClientPool.execute({
import { fileURLToPath } from 'node:url'
import { dirname, extname, join } from 'node:path'
import { DynamicThreadPool, availableParallelism } from 'poolifier'
+import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
import { type WorkerData } from './types.js'
const workerFile = join(
`worker${extname(fileURLToPath(import.meta.url))}`
)
-export const smtpClientPool = new DynamicThreadPool<WorkerData>(
- 1,
- availableParallelism(),
- workerFile,
- {
- enableTasksQueue: true,
- tasksQueueOptions: {
- concurrency: 8
- },
- errorHandler: (e: Error) => {
- console.error('Thread worker error:', e)
- }
+export const smtpClientPool = new DynamicThreadPool<
+WorkerData,
+SMTPTransport.SentMessageInfo
+>(1, availableParallelism(), workerFile, {
+ enableTasksQueue: true,
+ tasksQueueOptions: {
+ concurrency: 8
+ },
+ errorHandler: (e: Error) => {
+ console.error('Thread worker error:', e)
}
-)
+})
import { ThreadWorker } from 'poolifier'
import { createTransport } from 'nodemailer'
import type Mail from 'nodemailer/lib/mailer/index.js'
+import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
import { type WorkerData } from './types.js'
-class SmtpClientWorker extends ThreadWorker<WorkerData> {
+class SmtpClientWorker extends ThreadWorker<
+WorkerData,
+SMTPTransport.SentMessageInfo
+> {
public constructor () {
super({
nodemailer: async (workerData?: WorkerData) => {
- await createTransport(workerData?.smtpTransport).sendMail(
+ return await createTransport(workerData?.smtpTransport).sendMail(
workerData?.mail as Mail.Options
)
}