@razmatinyan/nuxt-email 0.1.0 → 0.1.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/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# nuxt-email
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@razmatinyan/nuxt-email)
|
|
4
|
+
[](https://www.npmjs.com/package/@razmatinyan/nuxt-email)
|
|
5
|
+
[](https://github.com/razmatinyan/nuxt-email/actions/workflows/ci.yml)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
3
8
|
Transactional email for Nuxt 4: a provider-agnostic API, Vue-powered templates, and type-safe server composables.
|
|
4
9
|
|
|
5
10
|
- 📨 **One API, many providers** — Resend, SendGrid, Postmark, SMTP, and a console provider for local dev
|
|
@@ -9,6 +14,11 @@ Transactional email for Nuxt 4: a provider-agnostic API, Vue-powered templates,
|
|
|
9
14
|
- 🔁 **Automatic retries** on transient failures, plus batch sending with a concurrency limit
|
|
10
15
|
- 🛠 **Nuxt DevTools tab** — browse templates, live-preview them, send a test, and watch a send log
|
|
11
16
|
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- Nuxt `>=4.0.0`
|
|
20
|
+
- Node.js 20.19+ or 22+
|
|
21
|
+
|
|
12
22
|
## Quick Setup
|
|
13
23
|
|
|
14
24
|
```bash
|
|
@@ -145,6 +155,8 @@ await sendEmail({
|
|
|
145
155
|
|
|
146
156
|
The template is rendered to HTML on the server, CSS is inlined for email-client compatibility, and a plain-text fallback is generated automatically. Style with inline `style` attributes or `<style>` blocks inside the `<template>` — SFC `<style>` blocks are stripped during compilation and won't be inlined.
|
|
147
157
|
|
|
158
|
+
Templates are collected at build time, so restart the dev server after adding or renaming a `.vue` template.
|
|
159
|
+
|
|
148
160
|
### Preview data
|
|
149
161
|
|
|
150
162
|
Export `previewProps` from a plain `<script>` block to give the dev preview and DevTools sample data:
|
|
@@ -220,9 +232,9 @@ await sendEmail({ to: 'me@example.com', subject: 'Test', template: 'welcome', pr
|
|
|
220
232
|
|
|
221
233
|
## Reliability & validation
|
|
222
234
|
|
|
235
|
+
- **Required fields** — every send needs a `to`, a `subject`, and at least one of `html`, `text`, or `template`. A `from` is required for non-`console` providers (set `email.from` or pass `from` per call). Missing any of these throws before the provider is called.
|
|
223
236
|
- **Retries** — failures that look transient (HTTP 429/5xx, timeouts, connection resets) are retried up to `retries` times with a growing delay. Client errors (4xx) are not retried.
|
|
224
237
|
- **Validation** — recipient addresses (`to`/`cc`/`bcc`/`replyTo`) and `from` are validated, `"Name <email>"` form is accepted, and newlines are rejected to prevent header injection. Attachments must have a `filename` and `content`.
|
|
225
|
-
- **Prerendering** — sends are skipped during `nuxi generate` / prerendering and return a no-op success.
|
|
226
238
|
|
|
227
239
|
## DevTools
|
|
228
240
|
|
|
@@ -240,6 +252,24 @@ These dev-only routes back the tab (and are handy on their own):
|
|
|
240
252
|
|
|
241
253
|
Set `preview: false` to disable them.
|
|
242
254
|
|
|
255
|
+
## Dev vs production
|
|
256
|
+
|
|
257
|
+
The send API (`sendEmail` / `sendBatch`) behaves the same in both modes. The differences are automatic:
|
|
258
|
+
|
|
259
|
+
- **The DevTools tab and every `/_email/*` route are dev-only** — registered only when Nuxt runs in dev mode (and `preview` is enabled), so they add nothing to your production bundle. Don't build app logic that depends on them.
|
|
260
|
+
- **The in-session send log is dev-only** and is tree-shaken out of production builds.
|
|
261
|
+
- **Sends are skipped during prerendering** (`nuxi generate`) and return a no-op success, so static generation never sends real email.
|
|
262
|
+
|
|
263
|
+
A common setup is the `console` provider locally and a real provider in production:
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
email: {
|
|
267
|
+
provider: process.env.NODE_ENV === 'production' ? 'resend' : 'console',
|
|
268
|
+
from: 'App <no-reply@app.com>',
|
|
269
|
+
apiKey: process.env.NUXT_EMAIL_API_KEY,
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
243
273
|
## Configuration
|
|
244
274
|
|
|
245
275
|
| Option | Type | Default | Description |
|
package/dist/module.json
CHANGED
|
@@ -41,7 +41,7 @@ export class PostmarkProvider {
|
|
|
41
41
|
method: "POST",
|
|
42
42
|
headers: {
|
|
43
43
|
"X-Postmark-Server-Token": this.apiKey,
|
|
44
|
-
Accept: "application/json",
|
|
44
|
+
"Accept": "application/json",
|
|
45
45
|
"Content-Type": "application/json"
|
|
46
46
|
},
|
|
47
47
|
body
|
|
@@ -83,7 +83,7 @@ export class PostmarkProvider {
|
|
|
83
83
|
await $fetch("https://api.postmarkapp.com/server", {
|
|
84
84
|
headers: {
|
|
85
85
|
"X-Postmark-Server-Token": this.apiKey,
|
|
86
|
-
Accept: "application/json"
|
|
86
|
+
"Accept": "application/json"
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
return true;
|
|
@@ -3,7 +3,7 @@ export function toBase64(content) {
|
|
|
3
3
|
return Buffer.from(content).toString("base64");
|
|
4
4
|
}
|
|
5
5
|
export function parseAddress(addr) {
|
|
6
|
-
const match = addr.match(/^(
|
|
6
|
+
const match = addr.match(/^([^<]*)<([^>]+)>$/);
|
|
7
7
|
if (match) return { name: match[1].trim(), email: match[2].trim() };
|
|
8
8
|
return { email: addr.trim() };
|
|
9
9
|
}
|