diff options
| author | Adam Soltys <[email protected]> | 2023-11-29 11:41:43 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-11-29 11:41:50 -0800 |
| commit | 8c5835fc2ca21fbe0dfd870d932253f24c995b48 (patch) | |
| tree | f14721047f8faa18fe33bb9086cfc6676afbd3f1 /lib/mail.js | |
| parent | ada148934ee075acf41e29592c7ca39868df34eb (diff) | |
| download | coinos-server-8c5835fc2ca21fbe0dfd870d932253f24c995b48.tar.gz coinos-server-8c5835fc2ca21fbe0dfd870d932253f24c995b48.zip | |
mail helper
Diffstat (limited to 'lib/mail.js')
| -rw-r--r-- | lib/mail.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/mail.js b/lib/mail.js new file mode 100644 index 00000000..1dc72b1f --- /dev/null +++ b/lib/mail.js @@ -0,0 +1,33 @@ +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"; + +export let templates = { + paymentSent: "templates/payments/sent.html" +}; + +export let mail = async (user, subject, template, params) => { + if (!user.email) return; + + let source = fs.readFileSync(path.join(__dirname, 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: config.support + }) + ); +}; |
