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