aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mail.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mail.js')
-rw-r--r--lib/mail.js33
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
+ })
+ );
+};