aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-29 11:41:43 -0800
committerAdam Soltys <[email protected]>2023-11-29 11:41:50 -0800
commit8c5835fc2ca21fbe0dfd870d932253f24c995b48 (patch)
treef14721047f8faa18fe33bb9086cfc6676afbd3f1 /lib
parentada148934ee075acf41e29592c7ca39868df34eb (diff)
downloadcoinos-server-8c5835fc2ca21fbe0dfd870d932253f24c995b48.tar.gz
coinos-server-8c5835fc2ca21fbe0dfd870d932253f24c995b48.zip
mail helper
Diffstat (limited to 'lib')
-rw-r--r--lib/mail.js33
-rw-r--r--lib/payments.js4
-rw-r--r--lib/whitelist.js1
3 files changed, 38 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
+ })
+ );
+};
diff --git a/lib/payments.js b/lib/payments.js
index 098c16f7..510f24e2 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -16,6 +16,7 @@ import EventEmitter from "events";
import crc32 from "buffer-crc32";
import { mqtt1, mqtt2 } from "$lib/mqtt";
import ln from "$lib/ln";
+import { mail, templates } from "$lib/mail";
export const types = {
internal: "internal",
@@ -98,6 +99,9 @@ export let debit = async (
l("sent", type, user.username, amount);
emit(user.id, "payment", p);
+ mail(user, "Payment sent", templates.paymentSent, {
+ username: user.username
+ });
return p;
};
diff --git a/lib/whitelist.js b/lib/whitelist.js
index 8da60b7f..1d722683 100644
--- a/lib/whitelist.js
+++ b/lib/whitelist.js
@@ -20,6 +20,7 @@ export default [
"linked",
"keys",
"locktime",
+ "nip5",
"payments",
"profile",
"prompt",