diff options
| author | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
| commit | fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch) | |
| tree | aa8f34e1692bd2d638a2c996eeadb58671d07aea /lib/mail.ts | |
| parent | 00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff) | |
| download | coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip | |
typescript
Diffstat (limited to 'lib/mail.ts')
| -rw-r--r-- | lib/mail.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/mail.ts b/lib/mail.ts new file mode 100644 index 00000000..16b3dbbf --- /dev/null +++ b/lib/mail.ts @@ -0,0 +1,44 @@ +import { l, err, warn } from "$lib/logging"; +import config from "$config"; +import { SESClient } from "@aws-sdk/client-ses"; +import { SendEmailCommand } from "@aws-sdk/client-ses"; +import handlebars from "handlebars"; +import fs from "fs"; +import path from "path"; + +let Charset = "UTF-8"; + +export let templates = { + verifyEmail: "templates/payments/verify.html", + paymentReceived: "templates/payments/received.html", + passwordReset: "templates/payments/reset.html", +}; + +export let mail = async (user, subject, template, params) => { + try { + l("sending mail", user.username, subject); + if (!user.email) return; + + let source = fs.readFileSync(template, "utf8"); + let html = handlebars.compile(source)(params); + + let client = new SESClient({ region: "us-east-2" }); + + await client.send( + new SendEmailCommand({ + Destination: { + ToAddresses: [user.email], + }, + Message: { + Body: { + Html: { Charset, Data: html }, + }, + Subject: { Charset, Data: subject }, + }, + Source: `"Coinos " <${config.support}>`, + }), + ); + } catch (e) { + err("failed to send email", e.message); + } +}; |
