nuxt-workmailer 1.1.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/README.md +119 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +12 -0
- package/dist/module.d.ts +12 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +23 -0
- package/dist/runtime/server/useNodeMailer.d.ts +5 -0
- package/dist/runtime/server/useNodeMailer.js +38 -0
- package/dist/types.d.mts +18 -0
- package/dist/types.d.ts +18 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# nuxt-workmailer
|
|
2
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
3
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
4
|
+
[![License][license-src]][license-href]
|
|
5
|
+
[![Nuxt][nuxt-src]][nuxt-href]
|
|
6
|
+
[![Volta][volta-src]][volta-href]
|
|
7
|
+
|
|
8
|
+
[![Buy me a coffee][buymecoffee-src]][buymeacoffee-href]
|
|
9
|
+
|
|
10
|
+
> Adds nodemailer to the Nuxt3
|
|
11
|
+
>
|
|
12
|
+
> This module can be used to send emails only from the server-side in Nuxt3.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
- Auto import server composable `useNodeMailer()`
|
|
16
|
+
- Add `sendEmail()` which inherits `from` argument
|
|
17
|
+
- Expose `nodemailer` original instance
|
|
18
|
+
- Using env variables for configuration
|
|
19
|
+
|
|
20
|
+
<!-- INSTALL/ -->
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Using ni
|
|
25
|
+
ni -D nuxt-nodemailer nodemailer
|
|
26
|
+
|
|
27
|
+
# Using pnpm
|
|
28
|
+
pnpm add -D nuxt-nodemailer nodemailer
|
|
29
|
+
|
|
30
|
+
# Using yarn
|
|
31
|
+
yarn add --dev nuxt-nodemailer nodemailer
|
|
32
|
+
|
|
33
|
+
# Using npm
|
|
34
|
+
npm install --save-dev nuxt-nodemailer nodemailer
|
|
35
|
+
```
|
|
36
|
+
<!-- /INSTALL -->
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Add `nuxt-nodemailer` to the `modules` sections of your `nuxt.config.js`.
|
|
41
|
+
|
|
42
|
+
> the configuration uses the same options as nodemailer you can find them [here](https://nodemailer.com/smtp/)
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
export default {
|
|
46
|
+
modules: [
|
|
47
|
+
'nuxt-nodemailer'
|
|
48
|
+
],
|
|
49
|
+
nodemailer: {
|
|
50
|
+
from: '"John Doe" <john@doe.com>',
|
|
51
|
+
host: 'smtp.mailtrap.io',
|
|
52
|
+
port: 465,
|
|
53
|
+
secure: true,
|
|
54
|
+
auth: {
|
|
55
|
+
user: 'john@doe.com',
|
|
56
|
+
pass: '',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Environment Variables
|
|
63
|
+
It's recommended to use environment variables for sensitive information like passwords.
|
|
64
|
+
|
|
65
|
+
each option in the `nodemailer` configuration can be overwritten using environment variables. It has to be prefixed with `NUXT_NODEMAILER_` and in uppercase.
|
|
66
|
+
|
|
67
|
+
For example, to overwrite the `auth.pass` and `from` options you can use the following environment variables:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
NUXT_NODEMAILER_AUTH_PASS=yourpassword
|
|
71
|
+
NUXT_NODEMAILER_FROM="..."
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
> Warning: You can overwrite only existing options in the `nodemailer` configuration in the `nuxt.config.js` file.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
In the server event handler, you can use the `useNodeMailer` composable to send emails.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
export default defineEventHandler(() => {
|
|
82
|
+
const { sendMail } = useNodeMailer()
|
|
83
|
+
|
|
84
|
+
return sendMail({ subject: 'Nuxt + nodemailer', text: 'Hello from nuxt-nodemailer!', to: 'john@doe.com' })
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
> the benefit of using `sendMail` is that it automatically inherits the `from` argument from the configuration and you don't have to specify it every time.
|
|
88
|
+
|
|
89
|
+
You can also use the `transport` with your config options or create brand new transport using `nodemailer` instance directly.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
export default defineEventHandler(() => {
|
|
93
|
+
const { transport, nodemailer } = useNodeMailer()
|
|
94
|
+
|
|
95
|
+
// you can create a new transport
|
|
96
|
+
return nodemailer.createTransport(...)
|
|
97
|
+
|
|
98
|
+
// or use the existing one
|
|
99
|
+
return transport.sendMail(...)
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
[npm-version-src]: https://img.shields.io/npm/v/nuxt-nodemailer/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
104
|
+
[npm-version-href]: https://npmjs.com/package/nuxt-nodemailer
|
|
105
|
+
|
|
106
|
+
[npm-downloads-src]: https://img.shields.io/npm/dt/nuxt-nodemailer.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
107
|
+
[npm-downloads-href]: https://npmjs.com/package/nuxt-nodemailer
|
|
108
|
+
|
|
109
|
+
[license-src]: https://img.shields.io/npm/l/nuxt-nodemailer.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
110
|
+
[license-href]: https://npmjs.com/package/nuxt-nodemailer
|
|
111
|
+
|
|
112
|
+
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
|
|
113
|
+
[nuxt-href]: https://nuxt.com
|
|
114
|
+
|
|
115
|
+
[volta-src]: https://user-images.githubusercontent.com/904724/209143798-32345f6c-3cf8-4e06-9659-f4ace4a6acde.svg
|
|
116
|
+
[volta-href]: https://volta.net/kleinpetr/nuxt-nodemailer
|
|
117
|
+
|
|
118
|
+
[buymecoffee-src]: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png
|
|
119
|
+
[buymeacoffee-href]: https://www.buymeacoffee.com/kleinpetr
|
package/dist/module.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
3
|
+
|
|
4
|
+
declare const _default: _nuxt_schema.NuxtModule<SMTPTransport.Options>;
|
|
5
|
+
|
|
6
|
+
declare module '@nuxt/schema' {
|
|
7
|
+
interface RuntimeConfig {
|
|
8
|
+
nodemailer: SMTPTransport.Options;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { _default as default };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
3
|
+
|
|
4
|
+
declare const _default: _nuxt_schema.NuxtModule<SMTPTransport.Options>;
|
|
5
|
+
|
|
6
|
+
declare module '@nuxt/schema' {
|
|
7
|
+
interface RuntimeConfig {
|
|
8
|
+
nodemailer: SMTPTransport.Options;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerImports } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "nuxt-workmailer",
|
|
6
|
+
configKey: "nodemailer"
|
|
7
|
+
},
|
|
8
|
+
setup(_options, _nuxt) {
|
|
9
|
+
_nuxt.options.runtimeConfig.nodemailer = {
|
|
10
|
+
..._options,
|
|
11
|
+
..._nuxt.options.runtimeConfig.nodemailer
|
|
12
|
+
};
|
|
13
|
+
const resolver = createResolver(import.meta.url);
|
|
14
|
+
addServerImports([
|
|
15
|
+
{
|
|
16
|
+
from: resolver.resolve("./runtime/server/useNodeMailer"),
|
|
17
|
+
name: "useNodeMailer"
|
|
18
|
+
}
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export { module as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
export const useNodeMailer = () => {
|
|
3
|
+
const { nodemailer } = useRuntimeConfig();
|
|
4
|
+
const sendMail = async (options) => {
|
|
5
|
+
if (import.meta.dev) {
|
|
6
|
+
const { createTransport } = await import("nodemailer");
|
|
7
|
+
const transport = createTransport(nodemailer);
|
|
8
|
+
const res = await transport.sendMail({
|
|
9
|
+
from: nodemailer.from,
|
|
10
|
+
...options
|
|
11
|
+
});
|
|
12
|
+
transport.close();
|
|
13
|
+
return res;
|
|
14
|
+
} else {
|
|
15
|
+
const { WorkerMailer } = await import("worker-mailer");
|
|
16
|
+
await WorkerMailer.send(
|
|
17
|
+
{
|
|
18
|
+
credentials: {
|
|
19
|
+
username: nodemailer.auth.user,
|
|
20
|
+
password: nodemailer.auth.pass
|
|
21
|
+
},
|
|
22
|
+
authType: String(nodemailer.authMethod).toLowerCase() || "plain",
|
|
23
|
+
host: nodemailer.host,
|
|
24
|
+
port: nodemailer.port,
|
|
25
|
+
secure: nodemailer.secure
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
from: nodemailer.from,
|
|
29
|
+
...options
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
nodemailer,
|
|
36
|
+
sendMail
|
|
37
|
+
};
|
|
38
|
+
};
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import type { } from './module.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare module '@nuxt/schema' {
|
|
6
|
+
export interface ModuleOptions {
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module 'nuxt/schema' {
|
|
12
|
+
export interface ModuleOptions {
|
|
13
|
+
[key: string]: any
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export type { default } from './module.js'
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import type { } from './module'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare module '@nuxt/schema' {
|
|
6
|
+
export interface ModuleOptions {
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module 'nuxt/schema' {
|
|
12
|
+
export interface ModuleOptions {
|
|
13
|
+
[key: string]: any
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export type { default } from './module'
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nuxt-workmailer",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "nodemailer Nuxt Module with Worker support",
|
|
5
|
+
"repository": "twinkelmann/nuxt-workmailer",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Petr Klein",
|
|
9
|
+
"email": "petr@kleinpetr.com"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/types.d.ts",
|
|
15
|
+
"import": "./dist/module.mjs",
|
|
16
|
+
"require": "./dist/module.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/module.cjs",
|
|
20
|
+
"types": "./dist/types.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"email",
|
|
26
|
+
"javascript",
|
|
27
|
+
"typescript",
|
|
28
|
+
"mail",
|
|
29
|
+
"nodemailer",
|
|
30
|
+
"npm-package",
|
|
31
|
+
"nuxt",
|
|
32
|
+
"nuxt-module",
|
|
33
|
+
"nuxt3",
|
|
34
|
+
"nuxt3-module",
|
|
35
|
+
"server",
|
|
36
|
+
"webdevelopment"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@nuxt/kit": "^3.11.2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"nodemailer": "^6.9.13",
|
|
43
|
+
"worker-mailer": "^1.1.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@nuxt/devtools": "^1.3.2",
|
|
47
|
+
"@nuxt/eslint-config": "^0.3.13",
|
|
48
|
+
"@nuxt/module-builder": "^0.7.0",
|
|
49
|
+
"@nuxt/schema": "^3.11.2",
|
|
50
|
+
"@nuxt/test-utils": "^3.13.1",
|
|
51
|
+
"@types/node": "^20.12.12",
|
|
52
|
+
"@types/nodemailer": "^6.4.15",
|
|
53
|
+
"changelogen": "^0.5.5",
|
|
54
|
+
"eslint": "^9.3.0",
|
|
55
|
+
"nodemailer": "^6.9.13",
|
|
56
|
+
"nuxt": "^3.11.2",
|
|
57
|
+
"prettier": "=3.5.3",
|
|
58
|
+
"typescript": "latest",
|
|
59
|
+
"vue-tsc": "^2.0.19",
|
|
60
|
+
"worker-mailer": "^1.1.1"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "nuxi dev playground",
|
|
64
|
+
"dev:build": "nuxi build playground",
|
|
65
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
66
|
+
"release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
67
|
+
"lint": "eslint . --fix",
|
|
68
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
69
|
+
}
|
|
70
|
+
}
|