@matthesketh/utopia-email 0.0.1
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 +21 -0
- package/README.md +58 -0
- package/dist/adapters/resend.cjs +88 -0
- package/dist/adapters/resend.d.cts +10 -0
- package/dist/adapters/resend.d.ts +10 -0
- package/dist/adapters/resend.js +53 -0
- package/dist/adapters/sendgrid.cjs +101 -0
- package/dist/adapters/sendgrid.d.cts +10 -0
- package/dist/adapters/sendgrid.d.ts +10 -0
- package/dist/adapters/sendgrid.js +66 -0
- package/dist/adapters/smtp.cjs +93 -0
- package/dist/adapters/smtp.d.cts +10 -0
- package/dist/adapters/smtp.d.ts +10 -0
- package/dist/adapters/smtp.js +58 -0
- package/dist/index.cjs +776 -0
- package/dist/index.d.cts +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +774 -0
- package/dist/types-C3uNsSmw.d.cts +75 -0
- package/dist/types-C3uNsSmw.d.ts +75 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matt Hesketh
|
|
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
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @matthesketh/utopia-email
|
|
2
|
+
|
|
3
|
+
Template-based email rendering for UtopiaJS. Render `.utopia` components to email-safe HTML with CSS inlining and plain text fallback. Adapter pattern for sending via SMTP, Resend, or SendGrid.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @matthesketh/utopia-email
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Install a provider SDK as needed:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add nodemailer # for SMTP
|
|
15
|
+
pnpm add resend # for Resend
|
|
16
|
+
pnpm add @sendgrid/mail # for SendGrid
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createMailer } from '@matthesketh/utopia-email';
|
|
23
|
+
import { smtpAdapter } from '@matthesketh/utopia-email/smtp';
|
|
24
|
+
import WelcomeEmail from './emails/Welcome.utopia';
|
|
25
|
+
|
|
26
|
+
const mailer = createMailer(smtpAdapter({
|
|
27
|
+
host: 'smtp.example.com',
|
|
28
|
+
port: 587,
|
|
29
|
+
auth: { user: 'user', pass: 'pass' },
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
await mailer.send({
|
|
33
|
+
to: 'user@example.com',
|
|
34
|
+
from: 'noreply@example.com',
|
|
35
|
+
subject: 'Welcome!',
|
|
36
|
+
component: WelcomeEmail,
|
|
37
|
+
props: { name: 'Alice' },
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
| Export | Description |
|
|
44
|
+
|--------|-------------|
|
|
45
|
+
| `createMailer(adapter)` | Create a mailer instance |
|
|
46
|
+
| `renderEmail(component, props?, options?)` | Render to `{ html, text, subject }` without sending |
|
|
47
|
+
| `inlineCSS(html, css)` | Inline CSS into `style=""` attributes |
|
|
48
|
+
| `htmlToText(html)` | Convert HTML to plain text |
|
|
49
|
+
|
|
50
|
+
**Built-in components:** `EmailLayout`, `EmailButton`, `EmailCard`, `EmailDivider`, `EmailHeading`, `EmailText`, `EmailImage`, `EmailColumns`, `EmailSpacer`.
|
|
51
|
+
|
|
52
|
+
**Adapters:** `@matthesketh/utopia-email/smtp`, `@matthesketh/utopia-email/resend`, `@matthesketh/utopia-email/sendgrid`.
|
|
53
|
+
|
|
54
|
+
See [docs/email.md](../../docs/email.md) for the full rendering pipeline, component reference, and type documentation.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
|
@@ -0,0 +1,88 @@
|
|
|
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/adapters/resend.ts
|
|
31
|
+
var resend_exports = {};
|
|
32
|
+
__export(resend_exports, {
|
|
33
|
+
resendAdapter: () => resendAdapter
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(resend_exports);
|
|
36
|
+
function resendAdapter(config) {
|
|
37
|
+
let client = null;
|
|
38
|
+
async function getClient() {
|
|
39
|
+
if (client) return client;
|
|
40
|
+
let Resend;
|
|
41
|
+
try {
|
|
42
|
+
const mod = await import("resend");
|
|
43
|
+
Resend = mod.Resend ?? mod.default;
|
|
44
|
+
} catch {
|
|
45
|
+
throw new Error(
|
|
46
|
+
'@matthesketh/utopia-email: "resend" package is required for the Resend adapter. Install it with: npm install resend'
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
client = new Resend(config.apiKey);
|
|
50
|
+
return client;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
async send(message) {
|
|
54
|
+
try {
|
|
55
|
+
const resend = await getClient();
|
|
56
|
+
const result = await resend.emails.send({
|
|
57
|
+
from: message.from,
|
|
58
|
+
to: Array.isArray(message.to) ? message.to : [message.to],
|
|
59
|
+
cc: message.cc ? Array.isArray(message.cc) ? message.cc : [message.cc] : void 0,
|
|
60
|
+
bcc: message.bcc ? Array.isArray(message.bcc) ? message.bcc : [message.bcc] : void 0,
|
|
61
|
+
reply_to: message.replyTo,
|
|
62
|
+
subject: message.subject,
|
|
63
|
+
html: message.html,
|
|
64
|
+
text: message.text,
|
|
65
|
+
headers: message.headers,
|
|
66
|
+
attachments: message.attachments?.map((a) => ({
|
|
67
|
+
filename: a.filename,
|
|
68
|
+
content: a.content,
|
|
69
|
+
content_type: a.contentType
|
|
70
|
+
}))
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
messageId: result.data?.id ?? result.id
|
|
75
|
+
};
|
|
76
|
+
} catch (err) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
error: err.message ?? String(err)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
resendAdapter
|
|
88
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { e as ResendConfig, E as EmailAdapter } from '../types-C3uNsSmw.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a Resend email adapter.
|
|
5
|
+
*
|
|
6
|
+
* Requires `resend` as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
declare function resendAdapter(config: ResendConfig): EmailAdapter;
|
|
9
|
+
|
|
10
|
+
export { resendAdapter };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { e as ResendConfig, E as EmailAdapter } from '../types-C3uNsSmw.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a Resend email adapter.
|
|
5
|
+
*
|
|
6
|
+
* Requires `resend` as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
declare function resendAdapter(config: ResendConfig): EmailAdapter;
|
|
9
|
+
|
|
10
|
+
export { resendAdapter };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/adapters/resend.ts
|
|
2
|
+
function resendAdapter(config) {
|
|
3
|
+
let client = null;
|
|
4
|
+
async function getClient() {
|
|
5
|
+
if (client) return client;
|
|
6
|
+
let Resend;
|
|
7
|
+
try {
|
|
8
|
+
const mod = await import("resend");
|
|
9
|
+
Resend = mod.Resend ?? mod.default;
|
|
10
|
+
} catch {
|
|
11
|
+
throw new Error(
|
|
12
|
+
'@matthesketh/utopia-email: "resend" package is required for the Resend adapter. Install it with: npm install resend'
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
client = new Resend(config.apiKey);
|
|
16
|
+
return client;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
async send(message) {
|
|
20
|
+
try {
|
|
21
|
+
const resend = await getClient();
|
|
22
|
+
const result = await resend.emails.send({
|
|
23
|
+
from: message.from,
|
|
24
|
+
to: Array.isArray(message.to) ? message.to : [message.to],
|
|
25
|
+
cc: message.cc ? Array.isArray(message.cc) ? message.cc : [message.cc] : void 0,
|
|
26
|
+
bcc: message.bcc ? Array.isArray(message.bcc) ? message.bcc : [message.bcc] : void 0,
|
|
27
|
+
reply_to: message.replyTo,
|
|
28
|
+
subject: message.subject,
|
|
29
|
+
html: message.html,
|
|
30
|
+
text: message.text,
|
|
31
|
+
headers: message.headers,
|
|
32
|
+
attachments: message.attachments?.map((a) => ({
|
|
33
|
+
filename: a.filename,
|
|
34
|
+
content: a.content,
|
|
35
|
+
content_type: a.contentType
|
|
36
|
+
}))
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
success: true,
|
|
40
|
+
messageId: result.data?.id ?? result.id
|
|
41
|
+
};
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
error: err.message ?? String(err)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
resendAdapter
|
|
53
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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/adapters/sendgrid.ts
|
|
31
|
+
var sendgrid_exports = {};
|
|
32
|
+
__export(sendgrid_exports, {
|
|
33
|
+
sendgridAdapter: () => sendgridAdapter
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(sendgrid_exports);
|
|
36
|
+
function sendgridAdapter(config) {
|
|
37
|
+
let client = null;
|
|
38
|
+
async function getClient() {
|
|
39
|
+
if (client) return client;
|
|
40
|
+
let sgMail;
|
|
41
|
+
try {
|
|
42
|
+
const mod = await import("@sendgrid/mail");
|
|
43
|
+
sgMail = mod.default ?? mod;
|
|
44
|
+
} catch {
|
|
45
|
+
throw new Error(
|
|
46
|
+
'@matthesketh/utopia-email: "@sendgrid/mail" package is required for the SendGrid adapter. Install it with: npm install @sendgrid/mail'
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
sgMail.setApiKey(config.apiKey);
|
|
50
|
+
client = sgMail;
|
|
51
|
+
return client;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
async send(message) {
|
|
55
|
+
try {
|
|
56
|
+
const sg = await getClient();
|
|
57
|
+
const msg = {
|
|
58
|
+
to: Array.isArray(message.to) ? message.to : [message.to],
|
|
59
|
+
from: message.from,
|
|
60
|
+
subject: message.subject,
|
|
61
|
+
html: message.html,
|
|
62
|
+
text: message.text
|
|
63
|
+
};
|
|
64
|
+
if (message.cc) {
|
|
65
|
+
msg.cc = Array.isArray(message.cc) ? message.cc : [message.cc];
|
|
66
|
+
}
|
|
67
|
+
if (message.bcc) {
|
|
68
|
+
msg.bcc = Array.isArray(message.bcc) ? message.bcc : [message.bcc];
|
|
69
|
+
}
|
|
70
|
+
if (message.replyTo) {
|
|
71
|
+
msg.replyTo = message.replyTo;
|
|
72
|
+
}
|
|
73
|
+
if (message.headers) {
|
|
74
|
+
msg.headers = message.headers;
|
|
75
|
+
}
|
|
76
|
+
if (message.attachments) {
|
|
77
|
+
msg.attachments = message.attachments.map((a) => ({
|
|
78
|
+
filename: a.filename,
|
|
79
|
+
content: typeof a.content === "string" ? a.content : a.content.toString("base64"),
|
|
80
|
+
type: a.contentType,
|
|
81
|
+
disposition: "attachment"
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
const [response] = await sg.send(msg);
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
messageId: response?.headers?.["x-message-id"]
|
|
88
|
+
};
|
|
89
|
+
} catch (err) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: err.message ?? String(err)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
sendgridAdapter
|
|
101
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { S as SendGridConfig, E as EmailAdapter } from '../types-C3uNsSmw.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a SendGrid email adapter.
|
|
5
|
+
*
|
|
6
|
+
* Requires `@sendgrid/mail` as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
declare function sendgridAdapter(config: SendGridConfig): EmailAdapter;
|
|
9
|
+
|
|
10
|
+
export { sendgridAdapter };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { S as SendGridConfig, E as EmailAdapter } from '../types-C3uNsSmw.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a SendGrid email adapter.
|
|
5
|
+
*
|
|
6
|
+
* Requires `@sendgrid/mail` as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
declare function sendgridAdapter(config: SendGridConfig): EmailAdapter;
|
|
9
|
+
|
|
10
|
+
export { sendgridAdapter };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/adapters/sendgrid.ts
|
|
2
|
+
function sendgridAdapter(config) {
|
|
3
|
+
let client = null;
|
|
4
|
+
async function getClient() {
|
|
5
|
+
if (client) return client;
|
|
6
|
+
let sgMail;
|
|
7
|
+
try {
|
|
8
|
+
const mod = await import("@sendgrid/mail");
|
|
9
|
+
sgMail = mod.default ?? mod;
|
|
10
|
+
} catch {
|
|
11
|
+
throw new Error(
|
|
12
|
+
'@matthesketh/utopia-email: "@sendgrid/mail" package is required for the SendGrid adapter. Install it with: npm install @sendgrid/mail'
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
sgMail.setApiKey(config.apiKey);
|
|
16
|
+
client = sgMail;
|
|
17
|
+
return client;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
async send(message) {
|
|
21
|
+
try {
|
|
22
|
+
const sg = await getClient();
|
|
23
|
+
const msg = {
|
|
24
|
+
to: Array.isArray(message.to) ? message.to : [message.to],
|
|
25
|
+
from: message.from,
|
|
26
|
+
subject: message.subject,
|
|
27
|
+
html: message.html,
|
|
28
|
+
text: message.text
|
|
29
|
+
};
|
|
30
|
+
if (message.cc) {
|
|
31
|
+
msg.cc = Array.isArray(message.cc) ? message.cc : [message.cc];
|
|
32
|
+
}
|
|
33
|
+
if (message.bcc) {
|
|
34
|
+
msg.bcc = Array.isArray(message.bcc) ? message.bcc : [message.bcc];
|
|
35
|
+
}
|
|
36
|
+
if (message.replyTo) {
|
|
37
|
+
msg.replyTo = message.replyTo;
|
|
38
|
+
}
|
|
39
|
+
if (message.headers) {
|
|
40
|
+
msg.headers = message.headers;
|
|
41
|
+
}
|
|
42
|
+
if (message.attachments) {
|
|
43
|
+
msg.attachments = message.attachments.map((a) => ({
|
|
44
|
+
filename: a.filename,
|
|
45
|
+
content: typeof a.content === "string" ? a.content : a.content.toString("base64"),
|
|
46
|
+
type: a.contentType,
|
|
47
|
+
disposition: "attachment"
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
const [response] = await sg.send(msg);
|
|
51
|
+
return {
|
|
52
|
+
success: true,
|
|
53
|
+
messageId: response?.headers?.["x-message-id"]
|
|
54
|
+
};
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
error: err.message ?? String(err)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
sendgridAdapter
|
|
66
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
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/adapters/smtp.ts
|
|
31
|
+
var smtp_exports = {};
|
|
32
|
+
__export(smtp_exports, {
|
|
33
|
+
smtpAdapter: () => smtpAdapter
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(smtp_exports);
|
|
36
|
+
function smtpAdapter(config) {
|
|
37
|
+
let transporter = null;
|
|
38
|
+
async function getTransporter() {
|
|
39
|
+
if (transporter) return transporter;
|
|
40
|
+
let nodemailer;
|
|
41
|
+
try {
|
|
42
|
+
nodemailer = await import("nodemailer");
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(
|
|
45
|
+
'@matthesketh/utopia-email: "nodemailer" package is required for the SMTP adapter. Install it with: npm install nodemailer'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
transporter = nodemailer.createTransport({
|
|
49
|
+
host: config.host,
|
|
50
|
+
port: config.port,
|
|
51
|
+
secure: config.secure ?? config.port === 465,
|
|
52
|
+
auth: config.auth
|
|
53
|
+
});
|
|
54
|
+
return transporter;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
async send(message) {
|
|
58
|
+
try {
|
|
59
|
+
const transport = await getTransporter();
|
|
60
|
+
const info = await transport.sendMail({
|
|
61
|
+
from: message.from,
|
|
62
|
+
to: Array.isArray(message.to) ? message.to.join(", ") : message.to,
|
|
63
|
+
cc: message.cc ? Array.isArray(message.cc) ? message.cc.join(", ") : message.cc : void 0,
|
|
64
|
+
bcc: message.bcc ? Array.isArray(message.bcc) ? message.bcc.join(", ") : message.bcc : void 0,
|
|
65
|
+
replyTo: message.replyTo,
|
|
66
|
+
subject: message.subject,
|
|
67
|
+
html: message.html,
|
|
68
|
+
text: message.text,
|
|
69
|
+
headers: message.headers,
|
|
70
|
+
attachments: message.attachments?.map((a) => ({
|
|
71
|
+
filename: a.filename,
|
|
72
|
+
content: a.content,
|
|
73
|
+
contentType: a.contentType,
|
|
74
|
+
encoding: a.encoding
|
|
75
|
+
}))
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
messageId: info.messageId
|
|
80
|
+
};
|
|
81
|
+
} catch (err) {
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
error: err.message ?? String(err)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
smtpAdapter
|
|
93
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { f as SmtpConfig, E as EmailAdapter } from '../types-C3uNsSmw.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create an SMTP email adapter using nodemailer.
|
|
5
|
+
*
|
|
6
|
+
* Requires `nodemailer` as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
declare function smtpAdapter(config: SmtpConfig): EmailAdapter;
|
|
9
|
+
|
|
10
|
+
export { smtpAdapter };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { f as SmtpConfig, E as EmailAdapter } from '../types-C3uNsSmw.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create an SMTP email adapter using nodemailer.
|
|
5
|
+
*
|
|
6
|
+
* Requires `nodemailer` as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
declare function smtpAdapter(config: SmtpConfig): EmailAdapter;
|
|
9
|
+
|
|
10
|
+
export { smtpAdapter };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/adapters/smtp.ts
|
|
2
|
+
function smtpAdapter(config) {
|
|
3
|
+
let transporter = null;
|
|
4
|
+
async function getTransporter() {
|
|
5
|
+
if (transporter) return transporter;
|
|
6
|
+
let nodemailer;
|
|
7
|
+
try {
|
|
8
|
+
nodemailer = await import("nodemailer");
|
|
9
|
+
} catch {
|
|
10
|
+
throw new Error(
|
|
11
|
+
'@matthesketh/utopia-email: "nodemailer" package is required for the SMTP adapter. Install it with: npm install nodemailer'
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
transporter = nodemailer.createTransport({
|
|
15
|
+
host: config.host,
|
|
16
|
+
port: config.port,
|
|
17
|
+
secure: config.secure ?? config.port === 465,
|
|
18
|
+
auth: config.auth
|
|
19
|
+
});
|
|
20
|
+
return transporter;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
async send(message) {
|
|
24
|
+
try {
|
|
25
|
+
const transport = await getTransporter();
|
|
26
|
+
const info = await transport.sendMail({
|
|
27
|
+
from: message.from,
|
|
28
|
+
to: Array.isArray(message.to) ? message.to.join(", ") : message.to,
|
|
29
|
+
cc: message.cc ? Array.isArray(message.cc) ? message.cc.join(", ") : message.cc : void 0,
|
|
30
|
+
bcc: message.bcc ? Array.isArray(message.bcc) ? message.bcc.join(", ") : message.bcc : void 0,
|
|
31
|
+
replyTo: message.replyTo,
|
|
32
|
+
subject: message.subject,
|
|
33
|
+
html: message.html,
|
|
34
|
+
text: message.text,
|
|
35
|
+
headers: message.headers,
|
|
36
|
+
attachments: message.attachments?.map((a) => ({
|
|
37
|
+
filename: a.filename,
|
|
38
|
+
content: a.content,
|
|
39
|
+
contentType: a.contentType,
|
|
40
|
+
encoding: a.encoding
|
|
41
|
+
}))
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
messageId: info.messageId
|
|
46
|
+
};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
error: err.message ?? String(err)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
smtpAdapter
|
|
58
|
+
};
|