Start implementing smtp
This commit is contained in:
parent
eee98516dd
commit
ed6c1cbd15
@ -51,6 +51,7 @@
|
|||||||
"@types/node": "^18.7.20",
|
"@types/node": "^18.7.20",
|
||||||
"@types/node-fetch": "^2.6.2",
|
"@types/node-fetch": "^2.6.2",
|
||||||
"@types/node-os-utils": "^1.3.0",
|
"@types/node-os-utils": "^1.3.0",
|
||||||
|
"@types/nodemailer": "^6.4.7",
|
||||||
"@types/probe-image-size": "^7.2.0",
|
"@types/probe-image-size": "^7.2.0",
|
||||||
"@types/sharp": "^0.31.0",
|
"@types/sharp": "^0.31.0",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
@ -95,6 +96,7 @@
|
|||||||
"node-2fa": "^2.0.3",
|
"node-2fa": "^2.0.3",
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"node-os-utils": "^1.3.7",
|
"node-os-utils": "^1.3.7",
|
||||||
|
"nodemailer": "^6.9.0",
|
||||||
"picocolors": "^1.0.0",
|
"picocolors": "^1.0.0",
|
||||||
"probe-image-size": "^7.2.3",
|
"probe-image-size": "^7.2.3",
|
||||||
"proxy-agent": "^5.0.0",
|
"proxy-agent": "^5.0.0",
|
||||||
|
@ -16,28 +16,29 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "missing-native-js-functions";
|
|
||||||
import { Server, ServerOptions } from "lambert-server";
|
|
||||||
import { Authentication, CORS } from "./middlewares/";
|
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
|
Email,
|
||||||
initDatabase,
|
initDatabase,
|
||||||
initEvent,
|
initEvent,
|
||||||
JSONReplacer,
|
JSONReplacer,
|
||||||
|
registerRoutes,
|
||||||
Sentry,
|
Sentry,
|
||||||
WebAuthn,
|
WebAuthn,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { ErrorHandler } from "./middlewares/ErrorHandler";
|
import { Request, Response, Router } from "express";
|
||||||
import { BodyParser } from "./middlewares/BodyParser";
|
import { Server, ServerOptions } from "lambert-server";
|
||||||
import { Router, Request, Response } from "express";
|
import "missing-native-js-functions";
|
||||||
|
import morgan from "morgan";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { red } from "picocolors";
|
||||||
|
import { Authentication, CORS } from "./middlewares/";
|
||||||
|
import { BodyParser } from "./middlewares/BodyParser";
|
||||||
|
import { ErrorHandler } from "./middlewares/ErrorHandler";
|
||||||
import { initRateLimits } from "./middlewares/RateLimit";
|
import { initRateLimits } from "./middlewares/RateLimit";
|
||||||
import TestClient from "./middlewares/TestClient";
|
import TestClient from "./middlewares/TestClient";
|
||||||
import { initTranslation } from "./middlewares/Translation";
|
import { initTranslation } from "./middlewares/Translation";
|
||||||
import morgan from "morgan";
|
|
||||||
import { initInstance } from "./util/handlers/Instance";
|
import { initInstance } from "./util/handlers/Instance";
|
||||||
import { registerRoutes } from "@fosscord/util";
|
|
||||||
import { red } from "picocolors";
|
|
||||||
|
|
||||||
export type FosscordServerOptions = ServerOptions;
|
export type FosscordServerOptions = ServerOptions;
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ export class FosscordServer extends Server {
|
|||||||
await initDatabase();
|
await initDatabase();
|
||||||
await Config.init();
|
await Config.init();
|
||||||
await initEvent();
|
await initEvent();
|
||||||
|
await Email.init();
|
||||||
await initInstance();
|
await initInstance();
|
||||||
await Sentry.init(this.app);
|
await Sentry.init(this.app);
|
||||||
WebAuthn.init();
|
WebAuthn.init();
|
||||||
|
@ -35,6 +35,7 @@ import {
|
|||||||
RegisterConfiguration,
|
RegisterConfiguration,
|
||||||
SecurityConfiguration,
|
SecurityConfiguration,
|
||||||
SentryConfiguration,
|
SentryConfiguration,
|
||||||
|
SMTPConfiguration,
|
||||||
TemplateConfiguration,
|
TemplateConfiguration,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
|
|
||||||
@ -58,4 +59,5 @@ export class ConfigValue {
|
|||||||
sentry: SentryConfiguration = new SentryConfiguration();
|
sentry: SentryConfiguration = new SentryConfiguration();
|
||||||
defaults: DefaultsConfiguration = new DefaultsConfiguration();
|
defaults: DefaultsConfiguration = new DefaultsConfiguration();
|
||||||
external: ExternalTokensConfiguration = new ExternalTokensConfiguration();
|
external: ExternalTokensConfiguration = new ExternalTokensConfiguration();
|
||||||
|
smtp: SMTPConfiguration = new SMTPConfiguration();
|
||||||
}
|
}
|
||||||
|
7
src/util/config/types/SMTPConfiguration.ts
Normal file
7
src/util/config/types/SMTPConfiguration.ts
Normal file
@ -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;
|
||||||
|
}
|
@ -34,5 +34,6 @@ export * from "./RegionConfiguration";
|
|||||||
export * from "./RegisterConfiguration";
|
export * from "./RegisterConfiguration";
|
||||||
export * from "./SecurityConfiguration";
|
export * from "./SecurityConfiguration";
|
||||||
export * from "./SentryConfiguration";
|
export * from "./SentryConfiguration";
|
||||||
export * from "./TemplateConfiguration";
|
export * from "./SMTPConfiguration";
|
||||||
export * from "./subconfigurations";
|
export * from "./subconfigurations";
|
||||||
|
export * from "./TemplateConfiguration";
|
||||||
|
@ -43,3 +43,34 @@ export function adjustEmail(email?: string): string | undefined {
|
|||||||
|
|
||||||
// return email;
|
// 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`);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user