@h3ravel/mail 11.0.0 → 11.0.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 +13 -1
- package/dist/index.cjs +287 -325
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -106
- package/dist/index.d.ts +117 -106
- package/dist/index.js +260 -290
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,316 +1,286 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/Drivers/LOGDriver.ts
|
|
5
1
|
import nodemailer from "nodemailer";
|
|
6
2
|
import Stream from "stream";
|
|
3
|
+
import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2";
|
|
4
|
+
import { ServiceProvider } from "@h3ravel/core";
|
|
5
|
+
|
|
6
|
+
//#region src/Drivers/LOGDriver.ts
|
|
7
7
|
var LOGDriver = class {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
info.message instanceof Stream.Readable && info.message.pipe(process.stdout);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
8
|
+
transporter;
|
|
9
|
+
constructor(_config) {
|
|
10
|
+
this.transporter = nodemailer.createTransport({
|
|
11
|
+
streamTransport: true,
|
|
12
|
+
newline: "unix"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async send(options) {
|
|
16
|
+
this.transporter.sendMail(options, (err, info) => {
|
|
17
|
+
if (err) throw err;
|
|
18
|
+
console.log(info.envelope);
|
|
19
|
+
console.log(info.messageId);
|
|
20
|
+
if (info.message instanceof Stream.Readable) info.message.pipe(process.stdout);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
26
23
|
};
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/Drivers/SendMailDriver.ts
|
|
30
27
|
var SendMailDriver = class {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
attachments: options.attachments
|
|
50
|
-
});
|
|
51
|
-
}
|
|
28
|
+
transporter;
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.transporter = nodemailer.createTransport({
|
|
31
|
+
sendmail: true,
|
|
32
|
+
path: config.path
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async send(options) {
|
|
36
|
+
return await this.transporter.sendMail({
|
|
37
|
+
to: options.to,
|
|
38
|
+
cc: options.cc,
|
|
39
|
+
bcc: options.bcc,
|
|
40
|
+
subject: options.subject,
|
|
41
|
+
html: options.html,
|
|
42
|
+
text: options.text,
|
|
43
|
+
attachments: options.attachments
|
|
44
|
+
});
|
|
45
|
+
}
|
|
52
46
|
};
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
import { SendEmailCommand, SESv2Client } from "@aws-sdk/client-sesv2";
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/Drivers/SESDriver.ts
|
|
57
50
|
var SESDriver = class {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
attachments: options.attachments
|
|
89
|
-
});
|
|
90
|
-
}
|
|
51
|
+
transporter;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
const sesClient = new SESv2Client({
|
|
54
|
+
region: config.region,
|
|
55
|
+
credentials: {
|
|
56
|
+
accessKeyId: config.key,
|
|
57
|
+
sessionToken: config.token,
|
|
58
|
+
secretAccessKey: config.secret
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
this.transporter = nodemailer.createTransport({
|
|
62
|
+
SES: {
|
|
63
|
+
sesClient,
|
|
64
|
+
SendEmailCommand
|
|
65
|
+
},
|
|
66
|
+
maxConnections: config.maxConnections,
|
|
67
|
+
sendingRate: config.sendingRate
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async send(options) {
|
|
71
|
+
return await this.transporter.sendMail({
|
|
72
|
+
to: options.to,
|
|
73
|
+
cc: options.cc,
|
|
74
|
+
bcc: options.bcc,
|
|
75
|
+
subject: options.subject,
|
|
76
|
+
html: options.html,
|
|
77
|
+
text: options.text,
|
|
78
|
+
attachments: options.attachments
|
|
79
|
+
});
|
|
80
|
+
}
|
|
91
81
|
};
|
|
92
82
|
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/Drivers/SMTPDriver.ts
|
|
95
85
|
var SMTPDriver = class {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
attachments: options.attachments
|
|
120
|
-
});
|
|
121
|
-
}
|
|
86
|
+
transporter;
|
|
87
|
+
constructor(config) {
|
|
88
|
+
this.transporter = nodemailer.createTransport({
|
|
89
|
+
host: config.host,
|
|
90
|
+
port: config.port,
|
|
91
|
+
secure: config.port === 465,
|
|
92
|
+
auth: {
|
|
93
|
+
user: config.auth.user,
|
|
94
|
+
pass: config.auth.pass
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async send(options) {
|
|
99
|
+
return await this.transporter.sendMail({
|
|
100
|
+
to: options.to,
|
|
101
|
+
cc: options.cc,
|
|
102
|
+
bcc: options.bcc,
|
|
103
|
+
subject: options.subject,
|
|
104
|
+
html: options.html,
|
|
105
|
+
text: options.text,
|
|
106
|
+
attachments: options.attachments
|
|
107
|
+
});
|
|
108
|
+
}
|
|
122
109
|
};
|
|
123
110
|
|
|
124
|
-
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/Mailable.ts
|
|
125
113
|
var Mailable = class {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
attachments: this.attachmentsList
|
|
189
|
-
};
|
|
190
|
-
}
|
|
114
|
+
toAddress;
|
|
115
|
+
ccAddresses;
|
|
116
|
+
bccAddresses;
|
|
117
|
+
subjectText;
|
|
118
|
+
htmlContent;
|
|
119
|
+
textContent;
|
|
120
|
+
viewPath;
|
|
121
|
+
viewData;
|
|
122
|
+
attachmentsList;
|
|
123
|
+
to(address) {
|
|
124
|
+
this.toAddress = address;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
cc(...addresses) {
|
|
128
|
+
this.ccAddresses = addresses;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
bcc(...addresses) {
|
|
132
|
+
this.bccAddresses = addresses;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
subject(subject) {
|
|
136
|
+
this.subjectText = subject;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
html(html) {
|
|
140
|
+
this.htmlContent = html;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
text(text) {
|
|
144
|
+
this.textContent = text;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
view(path, data = {}) {
|
|
148
|
+
this.viewPath = path;
|
|
149
|
+
this.viewData = data;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
attach(filename, filePath) {
|
|
153
|
+
if (!this.attachmentsList) this.attachmentsList = [];
|
|
154
|
+
this.attachmentsList.push({
|
|
155
|
+
filename,
|
|
156
|
+
path: filePath
|
|
157
|
+
});
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Called internally by Mailer
|
|
162
|
+
*/
|
|
163
|
+
getMessageOptions() {
|
|
164
|
+
return {
|
|
165
|
+
to: this.toAddress,
|
|
166
|
+
cc: this.ccAddresses,
|
|
167
|
+
bcc: this.bccAddresses,
|
|
168
|
+
subject: this.subjectText,
|
|
169
|
+
html: this.htmlContent,
|
|
170
|
+
text: this.textContent,
|
|
171
|
+
viewPath: this.viewPath,
|
|
172
|
+
viewData: this.viewData,
|
|
173
|
+
attachments: this.attachmentsList
|
|
174
|
+
};
|
|
175
|
+
}
|
|
191
176
|
};
|
|
192
177
|
|
|
193
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/Mailer.ts
|
|
194
180
|
var Mailer = class {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
try {
|
|
211
|
-
return this.driver.send(options);
|
|
212
|
-
} catch (error) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
181
|
+
constructor(driver, edgeRenderer) {
|
|
182
|
+
this.driver = driver;
|
|
183
|
+
this.edgeRenderer = edgeRenderer;
|
|
184
|
+
}
|
|
185
|
+
async send(mailable) {
|
|
186
|
+
await mailable.build();
|
|
187
|
+
const options = mailable.getMessageOptions();
|
|
188
|
+
if (options.viewPath && !options.html) options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
|
|
189
|
+
try {
|
|
190
|
+
return this.driver.send(options);
|
|
191
|
+
} catch {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
216
195
|
};
|
|
217
196
|
|
|
218
|
-
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/Service.ts
|
|
199
|
+
/**
|
|
200
|
+
* Service class to initialize and configure the mailer service
|
|
201
|
+
*/
|
|
219
202
|
var Service = class {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* SMTP driver factory
|
|
273
|
-
* @returns
|
|
274
|
-
*/
|
|
275
|
-
smtp: /* @__PURE__ */ __name(() => new SMTPDriver(mailConfig.smtp), "smtp"),
|
|
276
|
-
/**
|
|
277
|
-
* LOG driver factory for debugging
|
|
278
|
-
* @returns
|
|
279
|
-
*/
|
|
280
|
-
log: /* @__PURE__ */ __name(() => new LOGDriver(mailConfig.smtp), "log"),
|
|
281
|
-
/**
|
|
282
|
-
* Sendmail driver factory
|
|
283
|
-
* @returns
|
|
284
|
-
*/
|
|
285
|
-
sendmail: /* @__PURE__ */ __name(() => new SendMailDriver(mailConfig.sendmail), "sendmail")
|
|
286
|
-
};
|
|
287
|
-
return new Mailer((driver[config.get("mail.default")] ?? driver.smtp)(), async (viewPath, data) => await view(viewPath, data));
|
|
288
|
-
}
|
|
203
|
+
/**
|
|
204
|
+
* Initializes the mailer service with the given application instance
|
|
205
|
+
*
|
|
206
|
+
* @param app
|
|
207
|
+
* @returns
|
|
208
|
+
*/
|
|
209
|
+
static init(app) {
|
|
210
|
+
/**
|
|
211
|
+
* Resolve the view and config services from the container
|
|
212
|
+
*/
|
|
213
|
+
const view = app.make("view");
|
|
214
|
+
const config = app.make("config");
|
|
215
|
+
/**
|
|
216
|
+
* Configure mailer settings for different drivers
|
|
217
|
+
*/
|
|
218
|
+
const mailConfig = {
|
|
219
|
+
smtp: {
|
|
220
|
+
host: config.get("mail.mailers.smtp.host", "smtp.mailtrap.io"),
|
|
221
|
+
port: Number(config.get("mail.mailers.smtp.port", 2525)),
|
|
222
|
+
auth: {
|
|
223
|
+
user: config.get("mail.mailers.smtp.username", ""),
|
|
224
|
+
pass: config.get("mail.mailers.smtp.password", "")
|
|
225
|
+
},
|
|
226
|
+
opportunisticTLS: config.get("mail.mail气的mailers.smtp.encryption") === "tls",
|
|
227
|
+
connectionTimeout: config.get("mail.mailers.smtp.timeout"),
|
|
228
|
+
debug: false
|
|
229
|
+
},
|
|
230
|
+
ses: {
|
|
231
|
+
key: config.get("services.ses.key", ""),
|
|
232
|
+
token: config.get("services.ses.token", ""),
|
|
233
|
+
secret: config.get("services.ses.secret", ""),
|
|
234
|
+
region: config.get("services.ses.region", "us-east-1"),
|
|
235
|
+
maxConnections: config.get("mail.mailers.ses.connections", 10),
|
|
236
|
+
sendingRate: config.get("mail.mailers.ses.rate", 5)
|
|
237
|
+
},
|
|
238
|
+
sendmail: { path: config.get("mail.mailers.sendmail.path", "sendmail") }
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Define available mail drivers
|
|
242
|
+
*/
|
|
243
|
+
const driver = {
|
|
244
|
+
ses: () => new SESDriver(mailConfig.ses),
|
|
245
|
+
smtp: () => new SMTPDriver(mailConfig.smtp),
|
|
246
|
+
log: () => new LOGDriver(mailConfig.smtp),
|
|
247
|
+
sendmail: () => new SendMailDriver(mailConfig.sendmail)
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Initialize Mailer with the selected driver (default to SMTP if not specified)
|
|
251
|
+
* and a view rendering function
|
|
252
|
+
*/
|
|
253
|
+
return new Mailer((driver[config.get("mail.default")] ?? driver.smtp)(), async (viewPath, data) => await view(viewPath, data));
|
|
254
|
+
}
|
|
289
255
|
};
|
|
290
256
|
|
|
291
|
-
|
|
292
|
-
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/Providers/MailServiceProvider.ts
|
|
259
|
+
/**
|
|
260
|
+
* Mail delivery setup.
|
|
261
|
+
*
|
|
262
|
+
* Bind Mailer service.
|
|
263
|
+
* Load mail drivers (SMTP, SES, etc.).
|
|
264
|
+
* Register Mail facade.
|
|
265
|
+
*
|
|
266
|
+
*/
|
|
293
267
|
var MailServiceProvider = class extends ServiceProvider {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
MailServiceProvider,
|
|
309
|
-
Mailable,
|
|
310
|
-
Mailer,
|
|
311
|
-
SESDriver,
|
|
312
|
-
SMTPDriver,
|
|
313
|
-
SendMailDriver,
|
|
314
|
-
Service
|
|
268
|
+
static priority = 990;
|
|
269
|
+
register() {
|
|
270
|
+
/**
|
|
271
|
+
* Register Mailer instance
|
|
272
|
+
*/
|
|
273
|
+
this.app.singleton(Mailer, () => {
|
|
274
|
+
return Service.init(this.app);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
boot() {
|
|
278
|
+
/**
|
|
279
|
+
* Add logic here for global mail "from" address and others
|
|
280
|
+
*/
|
|
281
|
+
}
|
|
315
282
|
};
|
|
283
|
+
|
|
284
|
+
//#endregion
|
|
285
|
+
export { LOGDriver, MailServiceProvider, Mailable, Mailer, SESDriver, SMTPDriver, SendMailDriver, Service };
|
|
316
286
|
//# sourceMappingURL=index.js.map
|