@crowi/plugin-mail-smtp 0.1.0-alpha.0

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
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Sotaro KARASAWA <sotaro.k@gmail.com>
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ import { Transporter } from 'nodemailer';
2
+ import { z } from 'zod/v3';
3
+ import { MailSender, CrowiPlugin } from '@crowi/plugin-api';
4
+
5
+ declare const SmtpConfigSchema: z.ZodObject<{
6
+ /** SMTP server hostname. Empty disables the sender (send() throws). */
7
+ host: z.ZodDefault<z.ZodString>;
8
+ /** SMTP server port. 465 implies an implicit TLS connection. */
9
+ port: z.ZodDefault<z.ZodNumber>;
10
+ /** SMTP auth username. Leave empty for unauthenticated relays. */
11
+ user: z.ZodDefault<z.ZodString>;
12
+ /** SMTP auth password. */
13
+ password: z.ZodDefault<z.ZodString>;
14
+ /**
15
+ * Use an implicit TLS connection from the start. Leave false for
16
+ * STARTTLS on 587 / 25; the runtime also forces this on for port
17
+ * 465 regardless of this flag.
18
+ */
19
+ secure: z.ZodDefault<z.ZodBoolean>;
20
+ }, "strict", z.ZodTypeAny, {
21
+ host: string;
22
+ port: number;
23
+ user: string;
24
+ password: string;
25
+ secure: boolean;
26
+ }, {
27
+ host?: string | undefined;
28
+ port?: number | undefined;
29
+ user?: string | undefined;
30
+ password?: string | undefined;
31
+ secure?: boolean | undefined;
32
+ }>;
33
+ type SmtpConfig = z.infer<typeof SmtpConfigSchema>;
34
+ interface SmtpDriverState {
35
+ transport: Transporter | null;
36
+ }
37
+ declare const plugin: CrowiPlugin;
38
+
39
+ /**
40
+ * Build a nodemailer transport from config, or `null` when no host is
41
+ * configured (so the sender reports a clear "not configured" error
42
+ * rather than failing deep inside nodemailer).
43
+ */
44
+ declare function buildTransport(config: SmtpConfig): Transporter | null;
45
+ /**
46
+ * Build the mail sender. `send` reads `state.transport` once at the top
47
+ * so a concurrent `reconfigure` cannot swap the transport mid-send; the
48
+ * `EmailMessage` is a subset of nodemailer's `Mail.Options`, so it is
49
+ * passed through verbatim.
50
+ */
51
+ declare function createSmtpSender(driverState: SmtpDriverState): MailSender;
52
+
53
+ export { type SmtpDriverState, buildTransport, createSmtpSender, plugin as default };
@@ -0,0 +1,53 @@
1
+ import { Transporter } from 'nodemailer';
2
+ import { z } from 'zod/v3';
3
+ import { MailSender, CrowiPlugin } from '@crowi/plugin-api';
4
+
5
+ declare const SmtpConfigSchema: z.ZodObject<{
6
+ /** SMTP server hostname. Empty disables the sender (send() throws). */
7
+ host: z.ZodDefault<z.ZodString>;
8
+ /** SMTP server port. 465 implies an implicit TLS connection. */
9
+ port: z.ZodDefault<z.ZodNumber>;
10
+ /** SMTP auth username. Leave empty for unauthenticated relays. */
11
+ user: z.ZodDefault<z.ZodString>;
12
+ /** SMTP auth password. */
13
+ password: z.ZodDefault<z.ZodString>;
14
+ /**
15
+ * Use an implicit TLS connection from the start. Leave false for
16
+ * STARTTLS on 587 / 25; the runtime also forces this on for port
17
+ * 465 regardless of this flag.
18
+ */
19
+ secure: z.ZodDefault<z.ZodBoolean>;
20
+ }, "strict", z.ZodTypeAny, {
21
+ host: string;
22
+ port: number;
23
+ user: string;
24
+ password: string;
25
+ secure: boolean;
26
+ }, {
27
+ host?: string | undefined;
28
+ port?: number | undefined;
29
+ user?: string | undefined;
30
+ password?: string | undefined;
31
+ secure?: boolean | undefined;
32
+ }>;
33
+ type SmtpConfig = z.infer<typeof SmtpConfigSchema>;
34
+ interface SmtpDriverState {
35
+ transport: Transporter | null;
36
+ }
37
+ declare const plugin: CrowiPlugin;
38
+
39
+ /**
40
+ * Build a nodemailer transport from config, or `null` when no host is
41
+ * configured (so the sender reports a clear "not configured" error
42
+ * rather than failing deep inside nodemailer).
43
+ */
44
+ declare function buildTransport(config: SmtpConfig): Transporter | null;
45
+ /**
46
+ * Build the mail sender. `send` reads `state.transport` once at the top
47
+ * so a concurrent `reconfigure` cannot swap the transport mid-send; the
48
+ * `EmailMessage` is a subset of nodemailer's `Mail.Options`, so it is
49
+ * passed through verbatim.
50
+ */
51
+ declare function createSmtpSender(driverState: SmtpDriverState): MailSender;
52
+
53
+ export { type SmtpDriverState, buildTransport, createSmtpSender, plugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ buildTransport: () => buildTransport,
34
+ createSmtpSender: () => createSmtpSender,
35
+ default: () => index_default
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_nodemailer = __toESM(require("nodemailer"));
39
+ var import_v3 = require("zod/v3");
40
+ var SmtpConfigSchema = import_v3.z.object({
41
+ /** SMTP server hostname. Empty disables the sender (send() throws). */
42
+ host: import_v3.z.string().trim().default(""),
43
+ /** SMTP server port. 465 implies an implicit TLS connection. */
44
+ port: import_v3.z.coerce.number().int().min(1).max(65535).default(587),
45
+ /** SMTP auth username. Leave empty for unauthenticated relays. */
46
+ user: import_v3.z.string().trim().default(""),
47
+ /** SMTP auth password. */
48
+ password: import_v3.z.string().describe("@sensitive SMTP password").default(""),
49
+ /**
50
+ * Use an implicit TLS connection from the start. Leave false for
51
+ * STARTTLS on 587 / 25; the runtime also forces this on for port
52
+ * 465 regardless of this flag.
53
+ */
54
+ secure: import_v3.z.boolean().default(false)
55
+ }).strict();
56
+ var state = {
57
+ transport: null
58
+ };
59
+ var plugin = {
60
+ name: "@crowi/plugin-mail-smtp",
61
+ version: "0.1.0-dev",
62
+ configSchema: SmtpConfigSchema,
63
+ adminPlacement: {
64
+ label: "SMTP",
65
+ icon: "mail"
66
+ // section omitted: derived from registerMailSender → 'mail'
67
+ },
68
+ registerMailSender: (registry, ctx) => {
69
+ const host = applyConfigToState(ctx, state);
70
+ registry.register("smtp", createSmtpSender(state));
71
+ ctx.log.debug("registered smtp mail sender (host=%s)", host || "<unset>");
72
+ },
73
+ reconfigure: (ctx) => {
74
+ const host = applyConfigToState(ctx, state);
75
+ ctx.log.debug("reconfigured smtp mail sender (host=%s)", host || "<unset>");
76
+ }
77
+ };
78
+ var index_default = plugin;
79
+ function applyConfigToState(ctx, target) {
80
+ const config = ctx.config();
81
+ target.transport = buildTransport(config);
82
+ return config.host;
83
+ }
84
+ function buildTransport(config) {
85
+ if (!config.host) {
86
+ return null;
87
+ }
88
+ const secure = config.secure || config.port === 465;
89
+ return import_nodemailer.default.createTransport({
90
+ host: config.host,
91
+ port: config.port,
92
+ secure,
93
+ auth: config.user && config.password ? {
94
+ user: config.user,
95
+ pass: config.password
96
+ } : void 0,
97
+ tls: { rejectUnauthorized: false }
98
+ });
99
+ }
100
+ function createSmtpSender(driverState) {
101
+ return {
102
+ async send(message) {
103
+ const transport = driverState.transport;
104
+ if (!transport) {
105
+ throw new Error("@crowi/plugin-mail-smtp: SMTP host is not configured.");
106
+ }
107
+ await transport.sendMail({
108
+ to: message.to,
109
+ from: message.from,
110
+ subject: message.subject,
111
+ text: message.text,
112
+ html: message.html,
113
+ replyTo: message.replyTo,
114
+ cc: message.cc,
115
+ bcc: message.bcc
116
+ });
117
+ }
118
+ };
119
+ }
120
+ // Annotate the CommonJS export names for ESM import in node:
121
+ 0 && (module.exports = {
122
+ buildTransport,
123
+ createSmtpSender
124
+ });
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import nodemailer, { type Transporter } from 'nodemailer';\nimport { z } from 'zod/v3';\nimport type { CrowiPlugin, EmailMessage, MailSender, PluginContext } from '@crowi/plugin-api';\n\nconst SmtpConfigSchema = z\n .object({\n /** SMTP server hostname. Empty disables the sender (send() throws). */\n host: z.string().trim().default(''),\n /** SMTP server port. 465 implies an implicit TLS connection. */\n port: z.coerce.number().int().min(1).max(65535).default(587),\n /** SMTP auth username. Leave empty for unauthenticated relays. */\n user: z.string().trim().default(''),\n /** SMTP auth password. */\n password: z.string().describe('@sensitive SMTP password').default(''),\n /**\n * Use an implicit TLS connection from the start. Leave false for\n * STARTTLS on 587 / 25; the runtime also forces this on for port\n * 465 regardless of this flag.\n */\n secure: z.boolean().default(false),\n })\n .strict();\n\ntype SmtpConfig = z.infer<typeof SmtpConfigSchema>;\n\nexport interface SmtpDriverState {\n transport: Transporter | null;\n}\n\n/**\n * Module-scope state ref. `registerMailSender` initialises it from the\n * boot-time config; `send` snapshots the transport on each call;\n * `reconfigure` rebuilds it when the admin saves new values.\n */\nconst state: SmtpDriverState = {\n transport: null,\n};\n\nconst plugin: CrowiPlugin = {\n name: '@crowi/plugin-mail-smtp',\n version: '0.1.0-dev',\n configSchema: SmtpConfigSchema,\n adminPlacement: {\n label: 'SMTP',\n icon: 'mail',\n // section omitted: derived from registerMailSender → 'mail'\n },\n\n registerMailSender: (registry, ctx) => {\n const host = applyConfigToState(ctx, state);\n registry.register('smtp', createSmtpSender(state));\n ctx.log.debug('registered smtp mail sender (host=%s)', host || '<unset>');\n },\n\n reconfigure: (ctx) => {\n const host = applyConfigToState(ctx, state);\n ctx.log.debug('reconfigured smtp mail sender (host=%s)', host || '<unset>');\n },\n};\n\nexport default plugin;\n\n/** Apply config to `target` and return the configured host (for logging). */\nfunction applyConfigToState(ctx: PluginContext, target: SmtpDriverState): string {\n const config = ctx.config<SmtpConfig>();\n target.transport = buildTransport(config);\n return config.host;\n}\n\n/**\n * Build a nodemailer transport from config, or `null` when no host is\n * configured (so the sender reports a clear \"not configured\" error\n * rather than failing deep inside nodemailer).\n */\nexport function buildTransport(config: SmtpConfig): Transporter | null {\n if (!config.host) {\n return null;\n }\n const secure = config.secure || config.port === 465;\n return nodemailer.createTransport({\n host: config.host,\n port: config.port,\n secure,\n auth:\n config.user && config.password\n ? {\n user: config.user,\n pass: config.password,\n }\n : undefined,\n tls: { rejectUnauthorized: false },\n });\n}\n\n/**\n * Build the mail sender. `send` reads `state.transport` once at the top\n * so a concurrent `reconfigure` cannot swap the transport mid-send; the\n * `EmailMessage` is a subset of nodemailer's `Mail.Options`, so it is\n * passed through verbatim.\n */\nexport function createSmtpSender(driverState: SmtpDriverState): MailSender {\n return {\n async send(message: EmailMessage) {\n const transport = driverState.transport;\n if (!transport) {\n throw new Error('@crowi/plugin-mail-smtp: SMTP host is not configured.');\n }\n await transport.sendMail({\n to: message.to,\n from: message.from,\n subject: message.subject,\n text: message.text,\n html: message.html,\n replyTo: message.replyTo,\n cc: message.cc,\n bcc: message.bcc,\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA6C;AAC7C,gBAAkB;AAGlB,IAAM,mBAAmB,YACtB,OAAO;AAAA;AAAA,EAEN,MAAM,YAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;AAAA;AAAA,EAElC,MAAM,YAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,EAAE,QAAQ,GAAG;AAAA;AAAA,EAE3D,MAAM,YAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;AAAA;AAAA,EAElC,UAAU,YAAE,OAAO,EAAE,SAAS,0BAA0B,EAAE,QAAQ,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpE,QAAQ,YAAE,QAAQ,EAAE,QAAQ,KAAK;AACnC,CAAC,EACA,OAAO;AAaV,IAAM,QAAyB;AAAA,EAC7B,WAAW;AACb;AAEA,IAAM,SAAsB;AAAA,EAC1B,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AA,QACd,MAAM,QAAQ;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,IAAI,QAAQ;AAAA,QACZ,KAAK,QAAQ;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["nodemailer"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,89 @@
1
+ // src/index.ts
2
+ import nodemailer from "nodemailer";
3
+ import { z } from "zod/v3";
4
+ var SmtpConfigSchema = z.object({
5
+ /** SMTP server hostname. Empty disables the sender (send() throws). */
6
+ host: z.string().trim().default(""),
7
+ /** SMTP server port. 465 implies an implicit TLS connection. */
8
+ port: z.coerce.number().int().min(1).max(65535).default(587),
9
+ /** SMTP auth username. Leave empty for unauthenticated relays. */
10
+ user: z.string().trim().default(""),
11
+ /** SMTP auth password. */
12
+ password: z.string().describe("@sensitive SMTP password").default(""),
13
+ /**
14
+ * Use an implicit TLS connection from the start. Leave false for
15
+ * STARTTLS on 587 / 25; the runtime also forces this on for port
16
+ * 465 regardless of this flag.
17
+ */
18
+ secure: z.boolean().default(false)
19
+ }).strict();
20
+ var state = {
21
+ transport: null
22
+ };
23
+ var plugin = {
24
+ name: "@crowi/plugin-mail-smtp",
25
+ version: "0.1.0-dev",
26
+ configSchema: SmtpConfigSchema,
27
+ adminPlacement: {
28
+ label: "SMTP",
29
+ icon: "mail"
30
+ // section omitted: derived from registerMailSender → 'mail'
31
+ },
32
+ registerMailSender: (registry, ctx) => {
33
+ const host = applyConfigToState(ctx, state);
34
+ registry.register("smtp", createSmtpSender(state));
35
+ ctx.log.debug("registered smtp mail sender (host=%s)", host || "<unset>");
36
+ },
37
+ reconfigure: (ctx) => {
38
+ const host = applyConfigToState(ctx, state);
39
+ ctx.log.debug("reconfigured smtp mail sender (host=%s)", host || "<unset>");
40
+ }
41
+ };
42
+ var index_default = plugin;
43
+ function applyConfigToState(ctx, target) {
44
+ const config = ctx.config();
45
+ target.transport = buildTransport(config);
46
+ return config.host;
47
+ }
48
+ function buildTransport(config) {
49
+ if (!config.host) {
50
+ return null;
51
+ }
52
+ const secure = config.secure || config.port === 465;
53
+ return nodemailer.createTransport({
54
+ host: config.host,
55
+ port: config.port,
56
+ secure,
57
+ auth: config.user && config.password ? {
58
+ user: config.user,
59
+ pass: config.password
60
+ } : void 0,
61
+ tls: { rejectUnauthorized: false }
62
+ });
63
+ }
64
+ function createSmtpSender(driverState) {
65
+ return {
66
+ async send(message) {
67
+ const transport = driverState.transport;
68
+ if (!transport) {
69
+ throw new Error("@crowi/plugin-mail-smtp: SMTP host is not configured.");
70
+ }
71
+ await transport.sendMail({
72
+ to: message.to,
73
+ from: message.from,
74
+ subject: message.subject,
75
+ text: message.text,
76
+ html: message.html,
77
+ replyTo: message.replyTo,
78
+ cc: message.cc,
79
+ bcc: message.bcc
80
+ });
81
+ }
82
+ };
83
+ }
84
+ export {
85
+ buildTransport,
86
+ createSmtpSender,
87
+ index_default as default
88
+ };
89
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import nodemailer, { type Transporter } from 'nodemailer';\nimport { z } from 'zod/v3';\nimport type { CrowiPlugin, EmailMessage, MailSender, PluginContext } from '@crowi/plugin-api';\n\nconst SmtpConfigSchema = z\n .object({\n /** SMTP server hostname. Empty disables the sender (send() throws). */\n host: z.string().trim().default(''),\n /** SMTP server port. 465 implies an implicit TLS connection. */\n port: z.coerce.number().int().min(1).max(65535).default(587),\n /** SMTP auth username. Leave empty for unauthenticated relays. */\n user: z.string().trim().default(''),\n /** SMTP auth password. */\n password: z.string().describe('@sensitive SMTP password').default(''),\n /**\n * Use an implicit TLS connection from the start. Leave false for\n * STARTTLS on 587 / 25; the runtime also forces this on for port\n * 465 regardless of this flag.\n */\n secure: z.boolean().default(false),\n })\n .strict();\n\ntype SmtpConfig = z.infer<typeof SmtpConfigSchema>;\n\nexport interface SmtpDriverState {\n transport: Transporter | null;\n}\n\n/**\n * Module-scope state ref. `registerMailSender` initialises it from the\n * boot-time config; `send` snapshots the transport on each call;\n * `reconfigure` rebuilds it when the admin saves new values.\n */\nconst state: SmtpDriverState = {\n transport: null,\n};\n\nconst plugin: CrowiPlugin = {\n name: '@crowi/plugin-mail-smtp',\n version: '0.1.0-dev',\n configSchema: SmtpConfigSchema,\n adminPlacement: {\n label: 'SMTP',\n icon: 'mail',\n // section omitted: derived from registerMailSender → 'mail'\n },\n\n registerMailSender: (registry, ctx) => {\n const host = applyConfigToState(ctx, state);\n registry.register('smtp', createSmtpSender(state));\n ctx.log.debug('registered smtp mail sender (host=%s)', host || '<unset>');\n },\n\n reconfigure: (ctx) => {\n const host = applyConfigToState(ctx, state);\n ctx.log.debug('reconfigured smtp mail sender (host=%s)', host || '<unset>');\n },\n};\n\nexport default plugin;\n\n/** Apply config to `target` and return the configured host (for logging). */\nfunction applyConfigToState(ctx: PluginContext, target: SmtpDriverState): string {\n const config = ctx.config<SmtpConfig>();\n target.transport = buildTransport(config);\n return config.host;\n}\n\n/**\n * Build a nodemailer transport from config, or `null` when no host is\n * configured (so the sender reports a clear \"not configured\" error\n * rather than failing deep inside nodemailer).\n */\nexport function buildTransport(config: SmtpConfig): Transporter | null {\n if (!config.host) {\n return null;\n }\n const secure = config.secure || config.port === 465;\n return nodemailer.createTransport({\n host: config.host,\n port: config.port,\n secure,\n auth:\n config.user && config.password\n ? {\n user: config.user,\n pass: config.password,\n }\n : undefined,\n tls: { rejectUnauthorized: false },\n });\n}\n\n/**\n * Build the mail sender. `send` reads `state.transport` once at the top\n * so a concurrent `reconfigure` cannot swap the transport mid-send; the\n * `EmailMessage` is a subset of nodemailer's `Mail.Options`, so it is\n * passed through verbatim.\n */\nexport function createSmtpSender(driverState: SmtpDriverState): MailSender {\n return {\n async send(message: EmailMessage) {\n const transport = driverState.transport;\n if (!transport) {\n throw new Error('@crowi/plugin-mail-smtp: SMTP host is not configured.');\n }\n await transport.sendMail({\n to: message.to,\n from: message.from,\n subject: message.subject,\n text: message.text,\n html: message.html,\n replyTo: message.repl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rE,MAAI,CAAC,OAAO,MAAM;AAChB,WAAO;AAAA,EACT;AACA,QAAM,SAAS,OAAO,UAAU,OAAO,SAAS;AAChD,SAAO,WAAW,gBAAgB;AAAA,IAChC,MAAM,OAAO;AAAA,IACb,MAAM,OAAO;AAAA,IACb;AAAA,IACA,MACE,OAAO,QAAQ,OAAO,WAClB;AAAA,MACE,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,IACf,IACA;AAAA,IACN,KAAK,EAAE,oBAAoB,MAAM;AAAA,EACnC,CAAC;AACH;AAQO,SAAS,iBAAiB,aAA0C;AACzE,SAAO;AAAA,IACL,MAAM,KAAK,SAAuB;AAChC,YAAM,YAAY,YAAY;AAC9B,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,uDAAuD;AAAA,MACzE;AACA,YAAM,UAAU,SAAS;AAAA,QACvB,IAAI,QAAQ;AAAA,QACZ,MAAM,QAAQ;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,MAAM,QAAQ;AAAA,QACd,MAAM,QAAQ;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,IAAI,QAAQ;AAAA,QACZ,KAAK,QAAQ;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@crowi/plugin-mail-smtp",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "SMTP mail sender for Crowi 2.0. Default-on; delivers core-assembled email over SMTP via nodemailer.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "peerDependencies": {
23
+ "zod": "^4.4.3"
24
+ },
25
+ "dependencies": {
26
+ "nodemailer": "^8.0.9",
27
+ "@crowi/plugin-api": "^0.1.0-alpha.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^24",
31
+ "@types/nodemailer": "^8.0.0",
32
+ "tsup": "^8.3.5",
33
+ "typescript": "^5.8.3",
34
+ "zod": "^4.4.3",
35
+ "@crowi/plugin-api": "0.1.0-alpha.0",
36
+ "@crowi/tsconfig": "0.1.0-alpha.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "dev": "tsup --watch --no-clean",
41
+ "type-check": "tsc --noEmit"
42
+ }
43
+ }