| 8 | } |
| 9 | |
| 10 | export class AwsSesMailTransport implements MailTransport { |
| 11 | #client: nodemailer.Transporter; |
| 12 | |
| 13 | constructor(options: AwsSesMailTransportOptions) { |
| 14 | const ses = new awsSes.SESClient() |
| 15 | |
| 16 | this.#client = nodemailer.createTransport({ |
| 17 | SES: { |
| 18 | aws: awsSes, |
| 19 | ses |
| 20 | } |
| 21 | }) |
| 22 | } |
| 23 | |
| 24 | async send({to, from, replyTo, subject, react}: MailMessage): Promise<void> { |
| 25 | try { |
| 26 | await this.#client.sendMail({ |
| 27 | from: from, |
| 28 | to, |
| 29 | replyTo: replyTo, |
| 30 | subject, |
| 31 | html: await render(react), |
| 32 | }); |
| 33 | } |
| 34 | catch (error) { |
| 35 | if (error instanceof Error) { |
| 36 | console.error( |
| 37 | `Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}` |
| 38 | ); |
| 39 | throw new EmailError(error); |
| 40 | } else { |
| 41 | throw error; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | async sendPlainText({to, from, replyTo, subject, text, html}: PlainTextMailMessage): Promise<void> { |
| 47 | try { |
| 48 | await this.#client.sendMail({ |
| 49 | from: from, |
| 50 | to, |
| 51 | replyTo: replyTo, |
| 52 | subject, |
| 53 | ...(html ? { html, text } : { text }), |
| 54 | }); |
| 55 | } |
| 56 | catch (error) { |
| 57 | if (error instanceof Error) { |
| 58 | console.error( |
| 59 | `Failed to send email to ${to}, ${subject}. Error ${error.name}: ${error.message}` |
| 60 | ); |
| 61 | throw new EmailError(error); |
| 62 | } else { |
| 63 | throw error; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
nothing calls this directly
no outgoing calls
no test coverage detected