aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mail.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mail.js')
-rw-r--r--lib/mail.js41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/mail.js b/lib/mail.js
index 1dc72b1f..b5fda14d 100644
--- a/lib/mail.js
+++ b/lib/mail.js
@@ -1,3 +1,4 @@
+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";
@@ -5,29 +6,35 @@ import handlebars from "handlebars";
import fs from "fs";
import path from "path";
+let Charset = "UTF-8";
+
export let templates = {
paymentSent: "templates/payments/sent.html"
};
export let mail = async (user, subject, template, params) => {
- if (!user.email) return;
+ try {
+ if (!user.email) return;
- let source = fs.readFileSync(path.join(__dirname, template), "utf8");
- let html = handlebars.compile(source, params);
+ 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 }
+ 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 }
},
- Subject: { Charset, Data: subject }
- },
- Source: config.support
- })
- );
+ Source: config.support
+ })
+ );
+ } catch (e) {
+ err(e.message);
+ }
};