Start implementing smtp

This commit is contained in:
Puyodead1
2023-02-23 21:35:49 -05:00
committed by Puyodead1
parent eee98516dd
commit ed6c1cbd15
6 changed files with 55 additions and 10 deletions
+2
View File
@@ -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();
}
@@ -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;
}
+2 -1
View File
@@ -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";
+31
View File
@@ -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`);
});
},
};