@easy-cms/email-smtp 1.41.0 → 1.42.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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as _easy_cms_core from '@easy-cms/core';
1
2
  import { EmailAdapter } from '@easy-cms/core';
2
3
 
3
4
  interface SmtpOptions {
@@ -31,6 +32,15 @@ interface SmtpOptions {
31
32
  * ```
32
33
  */
33
34
  declare function smtp(options?: SmtpOptions): EmailAdapter;
35
+ /**
36
+ * SMTP as a provider an admin connects in Integrations → Email (with `emailPlugin()` from
37
+ * `@easy-cms/plugin-email`): host, port, user and password typed in the admin, not the code.
38
+ *
39
+ * ```ts
40
+ * emailPlugin({ providers: [...emailProviders, smtpProvider] })
41
+ * ```
42
+ */
43
+ declare const smtpProvider: _easy_cms_core.IntegrationConfig;
34
44
 
35
- export { smtp };
45
+ export { smtp, smtpProvider };
36
46
  export type { SmtpOptions };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ import { defineEmailProvider } from "@easy-cms/core";
2
3
  import nodemailer from "nodemailer";
3
4
  function smtp(options = {}) {
4
5
  let transporter;
@@ -62,7 +63,7 @@ function smtp(options = {}) {
62
63
  },
63
64
  async send(message) {
64
65
  const list = (value) => value === void 0 ? void 0 : typeof value === "string" ? value : [...value];
65
- await transport().sendMail({
66
+ const info = await transport().sendMail({
66
67
  from: message.from,
67
68
  to: list(message.to),
68
69
  cc: list(message.cc),
@@ -72,10 +73,50 @@ function smtp(options = {}) {
72
73
  ...message.html ? { html: message.html } : {},
73
74
  ...message.text ? { text: message.text } : {}
74
75
  });
76
+ return typeof info?.messageId === "string" ? { id: info.messageId } : void 0;
75
77
  }
76
78
  };
77
79
  return adapter;
78
80
  }
81
+ var smtpProvider = defineEmailProvider({
82
+ id: "smtp",
83
+ label: "SMTP",
84
+ description: {
85
+ en: "Any mail server: Gmail, Microsoft 365, your host\u2019s",
86
+ th: "\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E43\u0E14\u0E01\u0E47\u0E44\u0E14\u0E49 \u0E40\u0E0A\u0E48\u0E19 Gmail, Microsoft 365 \u0E2B\u0E23\u0E37\u0E2D\u0E02\u0E2D\u0E07\u0E42\u0E2E\u0E2A\u0E15\u0E4C"
87
+ },
88
+ icon: "mail",
89
+ docs: "https://easycms.dev/docs/email#smtp",
90
+ plugin: "@easy-cms/email-smtp",
91
+ fields: [
92
+ { name: "host", label: "Host", placeholder: "smtp.gmail.com", required: true },
93
+ { name: "port", label: "Port", placeholder: "587" },
94
+ { name: "user", label: { en: "User", th: "\u0E0A\u0E37\u0E48\u0E2D\u0E1C\u0E39\u0E49\u0E43\u0E0A\u0E49" } },
95
+ { name: "password", label: { en: "Password", th: "\u0E23\u0E2B\u0E31\u0E2A\u0E1C\u0E48\u0E32\u0E19" }, secret: true }
96
+ ],
97
+ create: (values) => fromValues(values),
98
+ async test(values) {
99
+ try {
100
+ const adapter = fromValues(values);
101
+ await adapter.verify?.();
102
+ return { ok: true, account: values.user || values.host || "" };
103
+ } catch (error) {
104
+ return { ok: false, message: error.message };
105
+ }
106
+ }
107
+ });
108
+ function fromValues(values) {
109
+ const port = Number(values.port || 587);
110
+ return smtp({
111
+ host: values.host ?? "",
112
+ port: Number.isFinite(port) ? port : 587,
113
+ // Empty: no login, rather than SMTP_USER from the environment.
114
+ user: values.user ?? "",
115
+ password: values.password ?? "",
116
+ ...values.from ? { from: values.from } : {}
117
+ });
118
+ }
79
119
  export {
80
- smtp
120
+ smtp,
121
+ smtpProvider
81
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/email-smtp",
3
- "version": "1.41.0",
3
+ "version": "1.42.0",
4
4
  "description": "SMTP email for Easy CMS (nodemailer): Gmail, Amazon SES, Resend, Mailgun and any SMTP server",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,11 +19,11 @@
19
19
  "nodemailer": "^10.0.12"
20
20
  },
21
21
  "peerDependencies": {
22
- "@easy-cms/core": "^1.41.0"
22
+ "@easy-cms/core": "^1.42.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/nodemailer": "^8.0.2",
26
- "@easy-cms/core": "^1.41.0"
26
+ "@easy-cms/core": "^1.42.0"
27
27
  },
28
28
  "engines": {
29
29
  "node": ">=22.12"