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