@wild-framework/mail-smtp 0.0.0-stage → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wild Framework contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # @wild-framework/mail-smtp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ SMTP mail driver for [Wild Framework](https://github.com/KhandaSoftware/wild-framework)'s mail package, backed by [nodemailer](https://nodemailer.com/).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @wild-framework/mail-smtp
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { SmtpMailProvider } from "@wild-framework/mail-smtp";
15
+
16
+ SmtpMailProvider.host = process.env.SMTP_HOST;
17
+ SmtpMailProvider.port = Number(process.env.SMTP_PORT ?? 587);
18
+ SmtpMailProvider.user = process.env.SMTP_USER;
19
+ SmtpMailProvider.pass = process.env.SMTP_PASS;
20
+ SmtpMailProvider.from = process.env.MAIL_FROM;
21
+
22
+ app.register(SmtpMailProvider);
23
+ // … mail is now SMTP-backed, resolved via app.resolve(Mail)
24
+ ```
25
+
26
+ Works with any SMTP server — Postmark, Resend, SendGrid, SES, Mailgun, self-hosted — or Mailpit/MailHog for local development.
27
+
28
+ ## Integration test
29
+
30
+ Point it at Mailpit and assert delivery via its HTTP API:
31
+
32
+ ```bash
33
+ SMTP_HOST=localhost SMTP_PORT=1025 MAILPIT_URL=http://localhost:8025 \
34
+ pnpm --filter @wild-framework/mail-smtp test
35
+ ```
36
+
37
+ Skips automatically when `SMTP_HOST` is not set.
38
+
39
+ ## License
40
+
41
+ MIT
@@ -0,0 +1,37 @@
1
+ import type { MailDriver, MailMessage } from "@wild-framework/mail";
2
+ import { type Transporter } from "nodemailer";
3
+ /**
4
+ * Configuration for the SMTP mail driver.
5
+ */
6
+ export interface SmtpMailConfig {
7
+ /** SMTP server host, e.g. `smtp.resend.com` or `localhost` (Mailpit). */
8
+ host: string;
9
+ /** SMTP server port. Defaults to `587` (or `465` when `secure` is true). */
10
+ port?: number;
11
+ /** Use TLS. Set `true` for port 465 (implicit TLS). */
12
+ secure?: boolean;
13
+ /** SMTP username. */
14
+ user?: string;
15
+ /** SMTP password. */
16
+ pass?: string;
17
+ /** Default `from` address when the message omits one. */
18
+ from?: string;
19
+ /** A pre-built transporter — for advanced use or tests. */
20
+ transporter?: Transporter;
21
+ }
22
+ /**
23
+ * SMTP mail driver implementing `MailDriver`.
24
+ *
25
+ * Backed by `nodemailer`. Works with any SMTP server — Postmark, Resend,
26
+ * SendGrid, SES, Mailgun, self-hosted, or Mailpit/MailHog for local testing.
27
+ */
28
+ export declare class SmtpMailDriver implements MailDriver {
29
+ private config;
30
+ private transporter;
31
+ constructor(config: SmtpMailConfig);
32
+ connect(): Promise<void>;
33
+ close(): Promise<void>;
34
+ send(message: MailMessage): Promise<void>;
35
+ private requireTransporter;
36
+ }
37
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAmB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,UAAU;IAGjC,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,WAAW,CAA4B;gBAE3B,MAAM,EAAE,cAAc;IAMpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/C,OAAO,CAAC,kBAAkB;CAgB7B"}
package/dist/driver.js ADDED
@@ -0,0 +1,54 @@
1
+ import nodemailer, {} from "nodemailer";
2
+ /**
3
+ * SMTP mail driver implementing `MailDriver`.
4
+ *
5
+ * Backed by `nodemailer`. Works with any SMTP server — Postmark, Resend,
6
+ * SendGrid, SES, Mailgun, self-hosted, or Mailpit/MailHog for local testing.
7
+ */
8
+ export class SmtpMailDriver {
9
+ config;
10
+ transporter = null;
11
+ constructor(config) {
12
+ this.config = config;
13
+ if (!config.host && !config.transporter) {
14
+ throw new Error("SmtpMailDriver requires a host (or an injected transporter).");
15
+ }
16
+ }
17
+ async connect() {
18
+ this.requireTransporter(); // materialise so config errors surface at boot
19
+ }
20
+ async close() {
21
+ // Only close transporters we created — an injected one is the caller's.
22
+ if (this.transporter && !this.config.transporter) {
23
+ this.transporter.close();
24
+ }
25
+ this.transporter = null;
26
+ }
27
+ async send(message) {
28
+ await this.requireTransporter().sendMail({
29
+ from: message.from ?? this.config.from,
30
+ to: message.to,
31
+ cc: message.cc,
32
+ bcc: message.bcc,
33
+ subject: message.subject,
34
+ text: message.text,
35
+ html: message.html,
36
+ });
37
+ }
38
+ requireTransporter() {
39
+ if (!this.transporter) {
40
+ this.transporter =
41
+ this.config.transporter ??
42
+ nodemailer.createTransport({
43
+ host: this.config.host,
44
+ port: this.config.port ?? (this.config.secure ? 465 : 587),
45
+ secure: this.config.secure ?? false,
46
+ auth: this.config.user || this.config.pass
47
+ ? { user: this.config.user, pass: this.config.pass }
48
+ : undefined,
49
+ });
50
+ }
51
+ return this.transporter;
52
+ }
53
+ }
54
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,EAAE,EAAoB,MAAM,YAAY,CAAC;AAsB1D;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAGH;IAFZ,WAAW,GAAuB,IAAI,CAAC;IAE/C,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;QACtC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;QACpF,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AAM,CAAC,IAAI;4BAChC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;4BACpD,CAAC,CAAC,SAAS;qBACtB,CAAC,CAAC;QACX,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;CACJ"}
@@ -0,0 +1,4 @@
1
+ export { SmtpMailDriver } from "./driver.js";
2
+ export type { SmtpMailConfig } from "./driver.js";
3
+ export { SmtpMailProvider } from "./provider.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { SmtpMailDriver } from "./driver.js";
2
+ export { SmtpMailProvider } from "./provider.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { Provider, Application } from "@wild-framework/core";
2
+ /**
3
+ * Registers an SMTP-backed mail system with the application.
4
+ *
5
+ * Static configuration (no-arg constructor requirement):
6
+ *
7
+ * ```ts
8
+ * SmtpMailProvider.host = process.env.SMTP_HOST!;
9
+ * SmtpMailProvider.port = Number(process.env.SMTP_PORT ?? 587);
10
+ * SmtpMailProvider.user = process.env.SMTP_USER;
11
+ * SmtpMailProvider.pass = process.env.SMTP_PASS;
12
+ * SmtpMailProvider.from = process.env.MAIL_FROM;
13
+ * ```
14
+ *
15
+ * Materialises the transporter on boot (fail-fast on bad config) and closes
16
+ * it on shutdown.
17
+ */
18
+ export declare class SmtpMailProvider implements Provider {
19
+ /** SMTP host. */
20
+ static host: string | undefined;
21
+ /** SMTP port. Defaults to 587 (465 when secure). */
22
+ static port: number | undefined;
23
+ /** Use implicit TLS (port 465). */
24
+ static secure: boolean;
25
+ /** SMTP username. */
26
+ static user: string | undefined;
27
+ /** SMTP password. */
28
+ static pass: string | undefined;
29
+ /** Default from address. */
30
+ static from: string | undefined;
31
+ private driver;
32
+ register(app: Application): void;
33
+ boot(): Promise<void>;
34
+ shutdown(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKlE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAiB,YAAW,QAAQ;IAC7C,iBAAiB;IACjB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,oDAAoD;IACpD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,mCAAmC;IACnC,MAAM,CAAC,MAAM,UAAS;IACtB,qBAAqB;IACrB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,qBAAqB;IACrB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,4BAA4B;IAC5B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAEhC,OAAO,CAAC,MAAM,CAA6B;IAE3C,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAgB1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
@@ -0,0 +1,54 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { Mail } from "@wild-framework/mail";
3
+ import { SmtpMailDriver } from "./driver.js";
4
+ /**
5
+ * Registers an SMTP-backed mail system with the application.
6
+ *
7
+ * Static configuration (no-arg constructor requirement):
8
+ *
9
+ * ```ts
10
+ * SmtpMailProvider.host = process.env.SMTP_HOST!;
11
+ * SmtpMailProvider.port = Number(process.env.SMTP_PORT ?? 587);
12
+ * SmtpMailProvider.user = process.env.SMTP_USER;
13
+ * SmtpMailProvider.pass = process.env.SMTP_PASS;
14
+ * SmtpMailProvider.from = process.env.MAIL_FROM;
15
+ * ```
16
+ *
17
+ * Materialises the transporter on boot (fail-fast on bad config) and closes
18
+ * it on shutdown.
19
+ */
20
+ export class SmtpMailProvider {
21
+ /** SMTP host. */
22
+ static host;
23
+ /** SMTP port. Defaults to 587 (465 when secure). */
24
+ static port;
25
+ /** Use implicit TLS (port 465). */
26
+ static secure = false;
27
+ /** SMTP username. */
28
+ static user;
29
+ /** SMTP password. */
30
+ static pass;
31
+ /** Default from address. */
32
+ static from;
33
+ driver;
34
+ register(app) {
35
+ const container = app.resolve(Container);
36
+ const driver = new SmtpMailDriver({
37
+ host: SmtpMailProvider.host ?? "",
38
+ port: SmtpMailProvider.port,
39
+ secure: SmtpMailProvider.secure,
40
+ user: SmtpMailProvider.user,
41
+ pass: SmtpMailProvider.pass,
42
+ from: SmtpMailProvider.from,
43
+ });
44
+ this.driver = driver;
45
+ container.singleton(Mail, () => new Mail(driver));
46
+ }
47
+ async boot() {
48
+ await this.driver?.connect();
49
+ }
50
+ async shutdown() {
51
+ await this.driver?.close();
52
+ }
53
+ }
54
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAA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  "name": "@wild-framework/mail-smtp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sphah",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Khandasoftware/wild-framework.git"
24
+ },
25
+ "description": "SMTP mail driver for Wild Framework's mail package (nodemailer).",
26
+ "keywords": [
27
+ "wild",
28
+ "framework",
29
+ "mail",
30
+ "email",
31
+ "smtp",
32
+ "nodemailer"
33
+ ],
34
+ "dependencies": {
35
+ "nodemailer": "^6.9.0",
36
+ "@wild-framework/core": "0.2.2",
37
+ "@wild-framework/container": "0.2.2",
38
+ "@wild-framework/mail": "0.2.2"
39
+ },
40
+ "devDependencies": {
41
+ "@types/nodemailer": "^6.4.0"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "clean": "rm -rf dist",
46
+ "test": "vitest run"
47
+ }
6
48
  }