1b463fa0b83ed257c6ec217b1da31de766ed8120
[poolifier.git] / examples / typescript / smtp-client-pool / src / main.ts
1 import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
2 import { smtpClientPool } from './pool.js'
3
4 const tos = ['bar@example.com, baz@example.com']
5
6 const smtpClientPoolPromises = new Set<Promise<SMTPTransport.SentMessageInfo>>()
7 for (const to of tos) {
8 smtpClientPoolPromises.add(
9 smtpClientPool.execute({
10 smtpTransport: {
11 host: 'smtp.domain.tld',
12 port: 465,
13 secure: true,
14 auth: {
15 user: 'REPLACE-WITH-YOUR-ALIAS@DOMAIN.TLD',
16 pass: 'REPLACE-WITH-YOUR-GENERATED-PASSWORD'
17 }
18 },
19 mail: {
20 from: '"Foo" <foo@domain.tld>',
21 to,
22 subject: 'Hello',
23 text: 'Hello world?',
24 html: '<b>Hello world?</b>'
25 }
26 })
27 )
28 }
29 try {
30 const now = performance.now()
31 await Promise.all(smtpClientPoolPromises)
32 const elapsedTime = performance.now() - now
33 console.info(
34 `Send in parallel in ${elapsedTime.toFixed(2)}ms ${
35 tos.length
36 } mails with SMTP client pool`
37 )
38 } catch (error) {
39 console.error(error)
40 }