@hz-9/a5-mail 0.2.0-alpha.26
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 +130 -0
- package/dist/all.d.ts +176 -0
- package/dist/const/index.d.ts +1 -0
- package/dist/const/index.js +3 -0
- package/dist/core/a5-mail.d.ts +31 -0
- package/dist/core/a5-mail.js +57 -0
- package/dist/core/a5-mail.module.d.ts +6 -0
- package/dist/core/a5-mail.module.js +26 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +20 -0
- package/dist/core/module-definition.d.ts +11 -0
- package/dist/core/module-definition.js +28 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/mail.d.ts +85 -0
- package/dist/interfaces/mail.js +3 -0
- package/dist/interfaces/module.d.ts +26 -0
- package/dist/interfaces/module.js +3 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @hz-9/a5-mail
|
|
2
|
+
|
|
3
|
+
Mail module for the @hz-9/a5-* series of repositories, based on [nodemailer](https://nodemailer.com/).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ 基于 nodemailer v7.x
|
|
8
|
+
- ✅ 支持多种传输方式(SMTP、Gmail、SES 等)
|
|
9
|
+
- ✅ 提供统一的邮件发送接口
|
|
10
|
+
- ✅ 支持同步和异步配置
|
|
11
|
+
- ✅ TypeScript 完整类型支持
|
|
12
|
+
- ✅ 全局模块支持
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @hz-9/a5-mail nodemailer
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### 1. 基础使用
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Module } from '@nestjs/common'
|
|
26
|
+
import { A5MailModule } from '@hz-9/a5-mail'
|
|
27
|
+
|
|
28
|
+
@Module({
|
|
29
|
+
imports: [
|
|
30
|
+
A5MailModule.forRoot({
|
|
31
|
+
host: 'smtp.gmail.com',
|
|
32
|
+
port: 587,
|
|
33
|
+
secure: false,
|
|
34
|
+
auth: {
|
|
35
|
+
user: 'your-email@gmail.com',
|
|
36
|
+
pass: 'your-app-password',
|
|
37
|
+
},
|
|
38
|
+
isGlobal: true,
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
export class AppModule {}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. 使用邮件服务
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Injectable } from '@nestjs/common'
|
|
49
|
+
import { A5Mail } from '@hz-9/a5-mail'
|
|
50
|
+
|
|
51
|
+
@Injectable()
|
|
52
|
+
export class UserService {
|
|
53
|
+
constructor(private readonly mail: A5Mail) {}
|
|
54
|
+
|
|
55
|
+
async sendWelcomeEmail(email: string, name: string) {
|
|
56
|
+
return this.mail.send({
|
|
57
|
+
from: 'noreply@example.com',
|
|
58
|
+
to: email,
|
|
59
|
+
subject: '欢迎加入',
|
|
60
|
+
html: `<h1>欢迎, ${name}!</h1>`,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. 异步配置
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { Module } from '@nestjs/common'
|
|
70
|
+
import { A5MailModule } from '@hz-9/a5-mail'
|
|
71
|
+
import { ConfigService } from '@nestjs/config'
|
|
72
|
+
|
|
73
|
+
@Module({
|
|
74
|
+
imports: [
|
|
75
|
+
A5MailModule.forRootAsync({
|
|
76
|
+
useFactory: (configService: ConfigService) => ({
|
|
77
|
+
host: configService.get('MAIL_HOST'),
|
|
78
|
+
port: configService.get('MAIL_PORT'),
|
|
79
|
+
secure: configService.get('MAIL_SECURE'),
|
|
80
|
+
auth: {
|
|
81
|
+
user: configService.get('MAIL_USER'),
|
|
82
|
+
pass: configService.get('MAIL_PASS'),
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
inject: [ConfigService],
|
|
86
|
+
}),
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
export class AppModule {}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API Documentation
|
|
93
|
+
|
|
94
|
+
### A5Mail
|
|
95
|
+
|
|
96
|
+
主要邮件服务类,提供以下方法:
|
|
97
|
+
|
|
98
|
+
#### `send(options: A5MailSendOptions): Promise<A5MailSendResponse>`
|
|
99
|
+
发送邮件。
|
|
100
|
+
|
|
101
|
+
#### `verify(): Promise<boolean>`
|
|
102
|
+
验证邮件传输配置是否正确。
|
|
103
|
+
|
|
104
|
+
#### `getInstance(): A5MailInstance`
|
|
105
|
+
获取原始 nodemailer Transporter 实例。
|
|
106
|
+
|
|
107
|
+
## Configuration Options
|
|
108
|
+
|
|
109
|
+
### A5MailConstructorOptions
|
|
110
|
+
|
|
111
|
+
邮件模块配置选项与 nodemailer.createTransport 的参数保持一致。
|
|
112
|
+
|
|
113
|
+
例如:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
interface A5MailConstructorOptions {
|
|
117
|
+
host?: string // SMTP 服务器地址
|
|
118
|
+
port?: number // SMTP 端口
|
|
119
|
+
secure?: boolean // 是否使用 TLS
|
|
120
|
+
auth?: { // 认证信息
|
|
121
|
+
user: string
|
|
122
|
+
pass: string
|
|
123
|
+
}
|
|
124
|
+
isGlobal?: boolean // 是否全局模块(默认:true)
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT
|
package/dist/all.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* A5 Mail Module - Mail sending for A5 framework based on nodemailer
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/// <reference types="node" />
|
|
7
|
+
|
|
8
|
+
import { ConfigurableModuleCls } from '@nestjs/common';
|
|
9
|
+
import { createTransport } from 'nodemailer';
|
|
10
|
+
import type { Transport } from 'nodemailer';
|
|
11
|
+
import type { TransportOptions } from 'nodemailer';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare const A5_MAIL_MODULE_OPTIONS: string | symbol;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A5 邮件服务类
|
|
20
|
+
*
|
|
21
|
+
* 提供统一的邮件发送接口,基于 nodemailer
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare class A5Mail {
|
|
26
|
+
private readonly instance;
|
|
27
|
+
constructor(options: A5MailConstructorOptions);
|
|
28
|
+
/**
|
|
29
|
+
* 发送邮件
|
|
30
|
+
*
|
|
31
|
+
* @param options - 邮件发送选项
|
|
32
|
+
* @returns 邮件发送响应
|
|
33
|
+
*/
|
|
34
|
+
send(options: A5MailSendOptions): Promise<A5MailSendResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* 验证邮件传输配置
|
|
37
|
+
*
|
|
38
|
+
* @returns 是否验证成功
|
|
39
|
+
*/
|
|
40
|
+
verify(): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* 获取原始邮件传输实例
|
|
43
|
+
*
|
|
44
|
+
* @returns 邮件传输实例
|
|
45
|
+
*/
|
|
46
|
+
getInstance(): A5MailInstance;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare const A5MailConfigurableModule: ConfigurableModuleCls<A5MailConstructorOptions, "forRoot", "createOptions", {
|
|
53
|
+
isGlobal: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A5 邮件模块构造选项接口
|
|
58
|
+
*
|
|
59
|
+
* 参数保持与 nodemailer.createTransport 一致
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare type A5MailConstructorOptions = TransportOptions | Transport;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A5 邮件传输实例接口
|
|
67
|
+
*
|
|
68
|
+
* 基于 nodemailer 的 Transporter 类型
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export declare type A5MailInstance = ReturnType<createTransport>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export declare class A5MailModule extends A5MailConfigurableModule {
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A5 缓存模块异步配置选项接口
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export declare interface A5MailModuleAsyncOptions {
|
|
86
|
+
/**
|
|
87
|
+
* 工厂函数,返回 A5MailModuleOptions 配置对象
|
|
88
|
+
*/
|
|
89
|
+
useFactory?: (...args: unknown[]) => Promise<A5MailModuleOptions> | A5MailModuleOptions;
|
|
90
|
+
/**
|
|
91
|
+
* 需要注入到 useFactory 函数中的依赖项
|
|
92
|
+
*/
|
|
93
|
+
inject?: unknown[];
|
|
94
|
+
/**
|
|
95
|
+
* 需要导入的模块列表
|
|
96
|
+
*/
|
|
97
|
+
imports?: unknown[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A5 缓存模块配置选项
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare type A5MailModuleOptions = A5MailConstructorOptions;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A5 邮件发送选项接口
|
|
109
|
+
*
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export declare interface A5MailSendOptions {
|
|
113
|
+
/**
|
|
114
|
+
* 发件人邮箱地址
|
|
115
|
+
*/
|
|
116
|
+
from?: string;
|
|
117
|
+
/**
|
|
118
|
+
* 收件人邮箱地址(单个或多个)
|
|
119
|
+
*/
|
|
120
|
+
to: string | string[];
|
|
121
|
+
/**
|
|
122
|
+
* 抄送收件人(可选)
|
|
123
|
+
*/
|
|
124
|
+
cc?: string | string[];
|
|
125
|
+
/**
|
|
126
|
+
* 密送收件人(可选)
|
|
127
|
+
*/
|
|
128
|
+
bcc?: string | string[];
|
|
129
|
+
/**
|
|
130
|
+
* 邮件主题
|
|
131
|
+
*/
|
|
132
|
+
subject: string;
|
|
133
|
+
/**
|
|
134
|
+
* 邮件正文(纯文本)
|
|
135
|
+
*/
|
|
136
|
+
text?: string;
|
|
137
|
+
/**
|
|
138
|
+
* 邮件正文(HTML)
|
|
139
|
+
*/
|
|
140
|
+
html?: string;
|
|
141
|
+
/**
|
|
142
|
+
* 附件数组
|
|
143
|
+
*/
|
|
144
|
+
attachments?: Array<{
|
|
145
|
+
filename: string;
|
|
146
|
+
content?: string | Buffer;
|
|
147
|
+
path?: string;
|
|
148
|
+
[key: string]: any;
|
|
149
|
+
}>;
|
|
150
|
+
/**
|
|
151
|
+
* 其他邮件选项
|
|
152
|
+
*/
|
|
153
|
+
[key: string]: any;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A5 邮件发送响应接口
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export declare interface A5MailSendResponse {
|
|
162
|
+
/**
|
|
163
|
+
* 响应消息 ID
|
|
164
|
+
*/
|
|
165
|
+
messageId?: string;
|
|
166
|
+
/**
|
|
167
|
+
* 响应状态
|
|
168
|
+
*/
|
|
169
|
+
response?: string;
|
|
170
|
+
/**
|
|
171
|
+
* 响应信息
|
|
172
|
+
*/
|
|
173
|
+
[key: string]: any;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { A5MailConstructorOptions, A5MailInstance, A5MailSendOptions, A5MailSendResponse } from '../interfaces/mail';
|
|
2
|
+
/**
|
|
3
|
+
* A5 邮件服务类
|
|
4
|
+
*
|
|
5
|
+
* 提供统一的邮件发送接口,基于 nodemailer
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class A5Mail {
|
|
10
|
+
private readonly instance;
|
|
11
|
+
constructor(options: A5MailConstructorOptions);
|
|
12
|
+
/**
|
|
13
|
+
* 发送邮件
|
|
14
|
+
*
|
|
15
|
+
* @param options - 邮件发送选项
|
|
16
|
+
* @returns 邮件发送响应
|
|
17
|
+
*/
|
|
18
|
+
send(options: A5MailSendOptions): Promise<A5MailSendResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* 验证邮件传输配置
|
|
21
|
+
*
|
|
22
|
+
* @returns 是否验证成功
|
|
23
|
+
*/
|
|
24
|
+
verify(): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取原始邮件传输实例
|
|
27
|
+
*
|
|
28
|
+
* @returns 邮件传输实例
|
|
29
|
+
*/
|
|
30
|
+
getInstance(): A5MailInstance;
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.A5Mail = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const nodemailer_1 = require("nodemailer");
|
|
15
|
+
/**
|
|
16
|
+
* A5 邮件服务类
|
|
17
|
+
*
|
|
18
|
+
* 提供统一的邮件发送接口,基于 nodemailer
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
let A5Mail = class A5Mail {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.instance = (0, nodemailer_1.createTransport)(options);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 发送邮件
|
|
28
|
+
*
|
|
29
|
+
* @param options - 邮件发送选项
|
|
30
|
+
* @returns 邮件发送响应
|
|
31
|
+
*/
|
|
32
|
+
async send(options) {
|
|
33
|
+
return this.instance.sendMail(options);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 验证邮件传输配置
|
|
37
|
+
*
|
|
38
|
+
* @returns 是否验证成功
|
|
39
|
+
*/
|
|
40
|
+
async verify() {
|
|
41
|
+
return this.instance.verify();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 获取原始邮件传输实例
|
|
45
|
+
*
|
|
46
|
+
* @returns 邮件传输实例
|
|
47
|
+
*/
|
|
48
|
+
getInstance() {
|
|
49
|
+
return this.instance;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.A5Mail = A5Mail;
|
|
53
|
+
exports.A5Mail = A5Mail = __decorate([
|
|
54
|
+
(0, common_1.Injectable)(),
|
|
55
|
+
__metadata("design:paramtypes", [Object])
|
|
56
|
+
], A5Mail);
|
|
57
|
+
//# sourceMappingURL=a5-mail.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.A5MailModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const a5_mail_1 = require("./a5-mail");
|
|
12
|
+
const module_definition_1 = require("./module-definition");
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
let A5MailModule = class A5MailModule extends module_definition_1.A5MailConfigurableModule {
|
|
17
|
+
};
|
|
18
|
+
exports.A5MailModule = A5MailModule;
|
|
19
|
+
exports.A5MailModule = A5MailModule = __decorate([
|
|
20
|
+
(0, common_1.Global)(),
|
|
21
|
+
(0, common_1.Module)({
|
|
22
|
+
providers: [a5_mail_1.A5Mail],
|
|
23
|
+
exports: [a5_mail_1.A5Mail],
|
|
24
|
+
})
|
|
25
|
+
], A5MailModule);
|
|
26
|
+
//# sourceMappingURL=a5-mail.module.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./a5-mail"), exports);
|
|
18
|
+
__exportStar(require("./a5-mail.module"), exports);
|
|
19
|
+
__exportStar(require("./module-definition"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { A5MailConstructorOptions } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export declare const A5MailConfigurableModule: import("@nestjs/common").ConfigurableModuleCls<A5MailConstructorOptions, "forRoot", "createOptions", {
|
|
6
|
+
isGlobal: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare const A5_MAIL_MODULE_OPTIONS: string | symbol;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A5_MAIL_MODULE_OPTIONS = exports.A5MailConfigurableModule = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
// eslint-disable-next-line @rushstack/typedef-var
|
|
6
|
+
const moduleDefinition = new common_1.ConfigurableModuleBuilder({
|
|
7
|
+
moduleName: 'A5Mail',
|
|
8
|
+
})
|
|
9
|
+
.setExtras({
|
|
10
|
+
isGlobal: true,
|
|
11
|
+
}, (definition, options) => ({
|
|
12
|
+
...definition,
|
|
13
|
+
global: options.isGlobal,
|
|
14
|
+
}))
|
|
15
|
+
.setClassMethodName('forRoot')
|
|
16
|
+
.setFactoryMethodName('createOptions')
|
|
17
|
+
.build();
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line @rushstack/typedef-var
|
|
22
|
+
exports.A5MailConfigurableModule = moduleDefinition.ConfigurableModuleClass;
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @rushstack/typedef-var
|
|
27
|
+
exports.A5_MAIL_MODULE_OPTIONS = moduleDefinition.MODULE_OPTIONS_TOKEN;
|
|
28
|
+
//# sourceMappingURL=module-definition.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
* A5 Mail Module - Mail sending for A5 framework based on nodemailer
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./const"), exports);
|
|
22
|
+
__exportStar(require("./core"), exports);
|
|
23
|
+
__exportStar(require("./interfaces"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./mail"), exports);
|
|
18
|
+
__exportStar(require("./module"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Transport, TransportOptions } from 'nodemailer';
|
|
3
|
+
/**
|
|
4
|
+
* A5 邮件模块构造选项接口
|
|
5
|
+
*
|
|
6
|
+
* 参数保持与 nodemailer.createTransport 一致
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type A5MailConstructorOptions = TransportOptions | Transport;
|
|
11
|
+
/**
|
|
12
|
+
* A5 邮件传输实例接口
|
|
13
|
+
*
|
|
14
|
+
* 基于 nodemailer 的 Transporter 类型
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type A5MailInstance = ReturnType<typeof import('nodemailer').createTransport>;
|
|
19
|
+
/**
|
|
20
|
+
* A5 邮件发送选项接口
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface A5MailSendOptions {
|
|
25
|
+
/**
|
|
26
|
+
* 发件人邮箱地址
|
|
27
|
+
*/
|
|
28
|
+
from?: string;
|
|
29
|
+
/**
|
|
30
|
+
* 收件人邮箱地址(单个或多个)
|
|
31
|
+
*/
|
|
32
|
+
to: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* 抄送收件人(可选)
|
|
35
|
+
*/
|
|
36
|
+
cc?: string | string[];
|
|
37
|
+
/**
|
|
38
|
+
* 密送收件人(可选)
|
|
39
|
+
*/
|
|
40
|
+
bcc?: string | string[];
|
|
41
|
+
/**
|
|
42
|
+
* 邮件主题
|
|
43
|
+
*/
|
|
44
|
+
subject: string;
|
|
45
|
+
/**
|
|
46
|
+
* 邮件正文(纯文本)
|
|
47
|
+
*/
|
|
48
|
+
text?: string;
|
|
49
|
+
/**
|
|
50
|
+
* 邮件正文(HTML)
|
|
51
|
+
*/
|
|
52
|
+
html?: string;
|
|
53
|
+
/**
|
|
54
|
+
* 附件数组
|
|
55
|
+
*/
|
|
56
|
+
attachments?: Array<{
|
|
57
|
+
filename: string;
|
|
58
|
+
content?: string | Buffer;
|
|
59
|
+
path?: string;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* 其他邮件选项
|
|
64
|
+
*/
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A5 邮件发送响应接口
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export interface A5MailSendResponse {
|
|
73
|
+
/**
|
|
74
|
+
* 响应消息 ID
|
|
75
|
+
*/
|
|
76
|
+
messageId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* 响应状态
|
|
79
|
+
*/
|
|
80
|
+
response?: string;
|
|
81
|
+
/**
|
|
82
|
+
* 响应信息
|
|
83
|
+
*/
|
|
84
|
+
[key: string]: any;
|
|
85
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { A5MailConstructorOptions } from './mail';
|
|
2
|
+
/**
|
|
3
|
+
* A5 缓存模块配置选项
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type A5MailModuleOptions = A5MailConstructorOptions;
|
|
8
|
+
/**
|
|
9
|
+
* A5 缓存模块异步配置选项接口
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface A5MailModuleAsyncOptions {
|
|
14
|
+
/**
|
|
15
|
+
* 工厂函数,返回 A5MailModuleOptions 配置对象
|
|
16
|
+
*/
|
|
17
|
+
useFactory?: (...args: unknown[]) => Promise<A5MailModuleOptions> | A5MailModuleOptions;
|
|
18
|
+
/**
|
|
19
|
+
* 需要注入到 useFactory 函数中的依赖项
|
|
20
|
+
*/
|
|
21
|
+
inject?: unknown[];
|
|
22
|
+
/**
|
|
23
|
+
* 需要导入的模块列表
|
|
24
|
+
*/
|
|
25
|
+
imports?: unknown[];
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hz-9/a5-mail",
|
|
3
|
+
"version": "0.2.0-alpha.26",
|
|
4
|
+
"description": "Mail module for the @hz-9/a5-* series of repositories, based on nodemailer.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nest",
|
|
7
|
+
"a5",
|
|
8
|
+
"a5-mail",
|
|
9
|
+
"mail",
|
|
10
|
+
"nodemailer"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://hz-9.github.io/a5/guide/a5-mail",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/hz-9/a5/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/hz-9/a5.git",
|
|
19
|
+
"directory": "library/mail"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Chen Zhen <heavenzhen999@163.com>",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./*": {
|
|
29
|
+
"require": "./dist/*.js",
|
|
30
|
+
"types": "./dist/*.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/**/*.{d.ts,js}"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"nodemailer": "^7.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@hz-9/eslint-config-airbnb-ts": "~0.6.0",
|
|
43
|
+
"@nestjs/cli": "^10.0.0",
|
|
44
|
+
"@nestjs/common": "^10.0.0",
|
|
45
|
+
"@nestjs/core": "^10.0.0",
|
|
46
|
+
"@nestjs/testing": "^10.0.0",
|
|
47
|
+
"@rushstack/heft": "0.66.1",
|
|
48
|
+
"@types/heft-jest": "~1.0.3",
|
|
49
|
+
"@types/node": "~20.3.1",
|
|
50
|
+
"@types/nodemailer": "^6.4.15",
|
|
51
|
+
"eslint": "^8.2.0",
|
|
52
|
+
"reflect-metadata": "^0.1.13",
|
|
53
|
+
"rxjs": "^7.8.1",
|
|
54
|
+
"ts-node": "^10.9.1",
|
|
55
|
+
"typescript": ">=5.0.0 <5.4.0",
|
|
56
|
+
"@hz-9/heft-nest-rig": "0.1.2",
|
|
57
|
+
"@hz-9/a5-core": "0.2.0-alpha.26"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@nestjs/common": "^10.0.0",
|
|
61
|
+
"@nestjs/core": "^10.0.0",
|
|
62
|
+
"reflect-metadata": "^0.1.13",
|
|
63
|
+
"rxjs": "^7.8.1",
|
|
64
|
+
"@hz-9/a5-core": "0.2.0-alpha.26"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "heft test-all --clean",
|
|
71
|
+
"lint": "heft lint",
|
|
72
|
+
"test": "heft test --clean",
|
|
73
|
+
"test:watch": "heft test-watch --clean"
|
|
74
|
+
}
|
|
75
|
+
}
|