summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-01-17 09:36:24 -0500
committerPuyodead1 <puyodead@protonmail.com>2023-02-23 21:35:49 -0500
commited6c1cbd1521d750bd9ac6823851057d00987332 (patch)
treeaf6bc78237f72eb76ef90b0d50ac1caa519508c2 /src/util
parentFix gateway encoding Date objects as {} when using erlpack. Fixes NaN/NaN/NaN... (diff)
downloadserver-ed6c1cbd1521d750bd9ac6823851057d00987332.tar.xz
Start implementing smtp
Diffstat (limited to 'src/util')
-rw-r--r--src/util/config/Config.ts2
-rw-r--r--src/util/config/types/SMTPConfiguration.ts7
-rw-r--r--src/util/config/types/index.ts3
-rw-r--r--src/util/util/Email.ts31
4 files changed, 42 insertions, 1 deletions
diff --git a/src/util/config/Config.ts b/src/util/config/Config.ts
index 122dadb5..583c1489 100644
--- a/src/util/config/Config.ts
+++ b/src/util/config/Config.ts
@@ -35,6 +35,7 @@ import {
 	RegisterConfiguration,
 	SecurityConfiguration,
 	SentryConfiguration,
+	SMTPConfiguration,
 	TemplateConfiguration,
 } from "../config";
 
@@ -58,4 +59,5 @@ export class ConfigValue {
 	sentry: SentryConfiguration = new SentryConfiguration();
 	defaults: DefaultsConfiguration = new DefaultsConfiguration();
 	external: ExternalTokensConfiguration = new ExternalTokensConfiguration();
+	smtp: SMTPConfiguration = new SMTPConfiguration();
 }
diff --git a/src/util/config/types/SMTPConfiguration.ts b/src/util/config/types/SMTPConfiguration.ts
new file mode 100644
index 00000000..e833376a
--- /dev/null
+++ b/src/util/config/types/SMTPConfiguration.ts
@@ -0,0 +1,7 @@
+export class SMTPConfiguration {
+	host: string | null = null;
+	port: number | null = null;
+	secure: boolean | null = null;
+	username: string | null = null;
+	password: string | null = null;
+}
diff --git a/src/util/config/types/index.ts b/src/util/config/types/index.ts
index 523ad186..3d8ed6df 100644
--- a/src/util/config/types/index.ts
+++ b/src/util/config/types/index.ts
@@ -34,5 +34,6 @@ export * from "./RegionConfiguration";
 export * from "./RegisterConfiguration";
 export * from "./SecurityConfiguration";
 export * from "./SentryConfiguration";
-export * from "./TemplateConfiguration";
+export * from "./SMTPConfiguration";
 export * from "./subconfigurations";
+export * from "./TemplateConfiguration";
diff --git a/src/util/util/Email.ts b/src/util/util/Email.ts
index 48d8cae1..d45eb9a1 100644
--- a/src/util/util/Email.ts
+++ b/src/util/util/Email.ts
@@ -43,3 +43,34 @@ export function adjustEmail(email?: string): string | undefined {
 
 	// return email;
 }
+
+export const Email: {
+	transporter: Transporter | null;
+	init: () => Promise<void>;
+} = {
+	transporter: null,
+	init: async function () {
+		const { host, port, secure, username, password } = Config.get().smtp;
+		if (!host || !port || !secure || !username || !password) return;
+		console.log(`[SMTP] connect: ${host}`);
+		this.transporter = nodemailer.createTransport({
+			host,
+			port,
+			secure,
+			auth: {
+				user: username,
+				pass: password,
+			},
+		});
+
+		await this.transporter.verify((error, _) => {
+			if (error) {
+				console.error(`[SMTP] error: ${error}`);
+				this.transporter?.close();
+				this.transporter = null;
+				return;
+			}
+			console.log(`[SMTP] Ready`);
+		});
+	},
+};