@h3ravel/mail 6.0.2 → 8.0.0
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/CHANGELOG.md +22 -0
- package/dist/index.cjs +158 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -3
- package/dist/index.d.ts +63 -3
- package/dist/index.js +144 -1
- package/dist/index.js.map +1 -1
- package/package.json +16 -4
- package/src/Contracts/Mailer.ts +20 -0
- package/src/Drivers/SMTPDriver.ts +31 -0
- package/src/Mailable.ts +77 -1
- package/src/Mailer.ts +21 -1
- package/src/Providers/MailServiceProvider.ts +37 -5
- package/src/index.ts +2 -1
- package/src/Contracts/.gitkeep +0 -0
- package/src/Drivers/SMTP.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @h3ravel/mail
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 79f4045: feat: add add exports to package.json
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [79f4045]
|
|
12
|
+
- @h3ravel/core@1.4.0
|
|
13
|
+
|
|
14
|
+
## 7.0.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- feat: implement full IoC container resolution
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
- @h3ravel/core@1.3.0
|
|
24
|
+
|
|
3
25
|
## 6.0.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
9
|
var __export = (target, all) => {
|
|
@@ -16,15 +18,148 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
|
|
21
31
|
// src/index.ts
|
|
22
32
|
var src_exports = {};
|
|
23
33
|
__export(src_exports, {
|
|
24
|
-
MailServiceProvider: () => MailServiceProvider
|
|
34
|
+
MailServiceProvider: () => MailServiceProvider,
|
|
35
|
+
Mailable: () => Mailable,
|
|
36
|
+
Mailer: () => Mailer,
|
|
37
|
+
SMTPDriver: () => SMTPDriver
|
|
25
38
|
});
|
|
26
39
|
module.exports = __toCommonJS(src_exports);
|
|
27
40
|
|
|
41
|
+
// src/Mailable.ts
|
|
42
|
+
var Mailable = class {
|
|
43
|
+
static {
|
|
44
|
+
__name(this, "Mailable");
|
|
45
|
+
}
|
|
46
|
+
toAddress;
|
|
47
|
+
ccAddresses;
|
|
48
|
+
bccAddresses;
|
|
49
|
+
subjectText;
|
|
50
|
+
htmlContent;
|
|
51
|
+
textContent;
|
|
52
|
+
viewPath;
|
|
53
|
+
viewData;
|
|
54
|
+
attachmentsList;
|
|
55
|
+
to(address) {
|
|
56
|
+
this.toAddress = address;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
cc(...addresses) {
|
|
60
|
+
this.ccAddresses = addresses;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
bcc(...addresses) {
|
|
64
|
+
this.bccAddresses = addresses;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
subject(subject) {
|
|
68
|
+
this.subjectText = subject;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
html(html) {
|
|
72
|
+
this.htmlContent = html;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
text(text) {
|
|
76
|
+
this.textContent = text;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
view(path, data = {}) {
|
|
80
|
+
this.viewPath = path;
|
|
81
|
+
this.viewData = data;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
attach(filename, filePath) {
|
|
85
|
+
if (!this.attachmentsList)
|
|
86
|
+
this.attachmentsList = [];
|
|
87
|
+
this.attachmentsList.push({
|
|
88
|
+
filename,
|
|
89
|
+
path: filePath
|
|
90
|
+
});
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Called internally by Mailer
|
|
95
|
+
*/
|
|
96
|
+
getMessageOptions() {
|
|
97
|
+
return {
|
|
98
|
+
to: this.toAddress,
|
|
99
|
+
cc: this.ccAddresses,
|
|
100
|
+
bcc: this.bccAddresses,
|
|
101
|
+
subject: this.subjectText,
|
|
102
|
+
html: this.htmlContent,
|
|
103
|
+
text: this.textContent,
|
|
104
|
+
viewPath: this.viewPath,
|
|
105
|
+
viewData: this.viewData,
|
|
106
|
+
attachments: this.attachmentsList
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/Mailer.ts
|
|
112
|
+
var Mailer = class {
|
|
113
|
+
static {
|
|
114
|
+
__name(this, "Mailer");
|
|
115
|
+
}
|
|
116
|
+
driver;
|
|
117
|
+
edgeRenderer;
|
|
118
|
+
constructor(driver, edgeRenderer) {
|
|
119
|
+
this.driver = driver;
|
|
120
|
+
this.edgeRenderer = edgeRenderer;
|
|
121
|
+
}
|
|
122
|
+
async send(mailable) {
|
|
123
|
+
await mailable.build();
|
|
124
|
+
const options = mailable.getMessageOptions();
|
|
125
|
+
if (options.viewPath && !options.html) {
|
|
126
|
+
options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
|
|
127
|
+
}
|
|
128
|
+
return this.driver.send(options);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/Drivers/SMTPDriver.ts
|
|
133
|
+
var import_nodemailer = __toESM(require("nodemailer"), 1);
|
|
134
|
+
var SMTPDriver = class {
|
|
135
|
+
static {
|
|
136
|
+
__name(this, "SMTPDriver");
|
|
137
|
+
}
|
|
138
|
+
transporter;
|
|
139
|
+
constructor(config) {
|
|
140
|
+
this.transporter = import_nodemailer.default.createTransport({
|
|
141
|
+
host: config.host,
|
|
142
|
+
port: config.port,
|
|
143
|
+
secure: config.port === 465,
|
|
144
|
+
auth: {
|
|
145
|
+
user: config.auth.user,
|
|
146
|
+
pass: config.auth.pass
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async send(options) {
|
|
151
|
+
return await this.transporter.sendMail({
|
|
152
|
+
to: options.to,
|
|
153
|
+
cc: options.cc,
|
|
154
|
+
bcc: options.bcc,
|
|
155
|
+
subject: options.subject,
|
|
156
|
+
html: options.html,
|
|
157
|
+
text: options.text,
|
|
158
|
+
attachments: options.attachments
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
28
163
|
// src/Providers/MailServiceProvider.ts
|
|
29
164
|
var import_core = require("@h3ravel/core");
|
|
30
165
|
var MailServiceProvider = class extends import_core.ServiceProvider {
|
|
@@ -33,10 +168,31 @@ var MailServiceProvider = class extends import_core.ServiceProvider {
|
|
|
33
168
|
}
|
|
34
169
|
static priority = 990;
|
|
35
170
|
register() {
|
|
171
|
+
this.app.singleton("mailer", () => {
|
|
172
|
+
const view = this.app.make("view");
|
|
173
|
+
const config = this.app.make("config");
|
|
174
|
+
const smtpConfig = {
|
|
175
|
+
host: config.get("mail.mailers.smtp.host", "smtp.mailtrap.io"),
|
|
176
|
+
port: Number(config.get("mail.mailers.smtp.port", 2525)),
|
|
177
|
+
auth: {
|
|
178
|
+
user: config.get("mail.mailers.smtp.username", ""),
|
|
179
|
+
pass: config.get("mail.mailers.smtp.password", "")
|
|
180
|
+
},
|
|
181
|
+
opportunisticTLS: config.get("mail.mailers.smtp.encryption") === "tls",
|
|
182
|
+
connectionTimeout: config.get("mail.mailers.smtp.timeout"),
|
|
183
|
+
debug: false
|
|
184
|
+
};
|
|
185
|
+
return new Mailer(new SMTPDriver(smtpConfig), async (viewPath, data) => await view(viewPath, data));
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
boot() {
|
|
36
189
|
}
|
|
37
190
|
};
|
|
38
191
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
192
|
0 && (module.exports = {
|
|
40
|
-
MailServiceProvider
|
|
193
|
+
MailServiceProvider,
|
|
194
|
+
Mailable,
|
|
195
|
+
Mailer,
|
|
196
|
+
SMTPDriver
|
|
41
197
|
});
|
|
42
198
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/Providers/MailServiceProvider.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Helpers';\nexport * from './Mailable';\nexport * from './Mailer';\nexport * from './Drivers/SES';\nexport * from './Drivers/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Mailable.ts","../src/Mailer.ts","../src/Drivers/SMTPDriver.ts","../src/Providers/MailServiceProvider.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Helpers';\nexport * from './Mailable';\nexport * from './Mailer';\nexport * from './Contracts/Mailer';\nexport * from './Drivers/SES';\nexport * from './Drivers/SMTPDriver';\nexport * from './Providers/MailServiceProvider';\n","import type { SendMailOptions } from \"./Contracts/Mailer\";\n\nexport abstract class Mailable {\n protected toAddress?: string;\n protected ccAddresses?: string[];\n protected bccAddresses?: string[];\n protected subjectText?: string;\n protected htmlContent?: string;\n protected textContent?: string;\n protected viewPath?: string;\n protected viewData?: Record<string, any>;\n protected attachmentsList?: SendMailOptions['attachments'];\n\n to (address: string) {\n this.toAddress = address;\n return this;\n }\n\n cc (...addresses: string[]) {\n this.ccAddresses = addresses;\n return this;\n }\n\n bcc (...addresses: string[]) {\n this.bccAddresses = addresses;\n return this;\n }\n\n subject (subject: string) {\n this.subjectText = subject;\n return this;\n }\n\n html (html: string) {\n this.htmlContent = html;\n return this;\n }\n\n text (text: string) {\n this.textContent = text;\n return this;\n }\n\n view (path: string, data: Record<string, any> = {}) {\n this.viewPath = path;\n this.viewData = data;\n return this;\n }\n\n attach (filename: string, filePath: string) {\n if (!this.attachmentsList) this.attachmentsList = [];\n this.attachmentsList.push({ filename, path: filePath });\n return this;\n }\n\n /**\n * Child classes should define build() like in Laravel\n */\n abstract build (): Promise<this> | this;\n\n /**\n * Called internally by Mailer\n */\n getMessageOptions (): SendMailOptions {\n return {\n to: this.toAddress,\n cc: this.ccAddresses,\n bcc: this.bccAddresses,\n subject: this.subjectText,\n html: this.htmlContent,\n text: this.textContent,\n viewPath: this.viewPath,\n viewData: this.viewData,\n attachments: this.attachmentsList\n };\n }\n}\n","import { MailDriverContract } from './Contracts/Mailer';\nimport { Mailable } from './Mailable';\n\nexport class Mailer {\n constructor(\n private driver: MailDriverContract,\n private edgeRenderer: (viewPath: string, data: Record<string, any>) => Promise<string>\n ) { }\n\n async send (mailable: Mailable) {\n await mailable.build();\n\n const options = mailable.getMessageOptions();\n\n if (options.viewPath && !options.html) {\n options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});\n }\n\n return this.driver.send(options);\n }\n}\n","import nodemailer, { type SendMailOptions, type TransportOptions } from 'nodemailer';\n\nimport { MailDriverContract, SMTPConfig } from '../Contracts/Mailer';\n\nexport class SMTPDriver implements MailDriverContract {\n private transporter;\n\n constructor(config: SMTPConfig) {\n this.transporter = nodemailer.createTransport({\n host: config.host,\n port: config.port,\n secure: config.port === 465, // auto decide based on port\n auth: {\n user: config.auth.user,\n pass: config.auth.pass\n }\n });\n }\n\n async send (options: SendMailOptions) {\n return await this.transporter.sendMail({\n to: options.to,\n cc: options.cc,\n bcc: options.bcc,\n subject: options.subject,\n html: options.html,\n text: options.text,\n attachments: options.attachments\n });\n }\n}\n","import { Mailer } from '../Mailer';\nimport { SMTPConfig } from '../Contracts/Mailer';\nimport { SMTPDriver } from '../Drivers/SMTPDriver';\nimport { ServiceProvider } from '@h3ravel/core';\n\n/**\n * Mail delivery setup.\n * \n * Bind Mailer service.\n * Load mail drivers (SMTP, SES, etc.).\n * Register Mail facade.\n * \n */\nexport class MailServiceProvider extends ServiceProvider {\n public static priority = 990;\n register () {\n /**\n * Register Mailer instance\n */\n\n this.app.singleton<any>('mailer', () => {\n // this.app.bind(Mailer, () => {\n const view = this.app.make('view');\n const config = this.app.make('config');\n\n const smtpConfig: SMTPConfig = {\n host: config.get('mail.mailers.smtp.host', 'smtp.mailtrap.io'),\n port: Number(config.get('mail.mailers.smtp.port', 2525)),\n auth: {\n user: config.get('mail.mailers.smtp.username', ''),\n pass: config.get('mail.mailers.smtp.password', ''),\n },\n opportunisticTLS: config.get('mail.mailers.smtp.encryption') === 'tls',\n connectionTimeout: config.get('mail.mailers.smtp.timeout'),\n debug: false,\n };\n\n return new Mailer(\n new SMTPDriver(smtpConfig),\n async (viewPath, data) => await view(viewPath, data)\n );\n });\n }\n\n boot () {\n /**\n * Add logic here for global mail \"from\" address and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I,2BAAA;QAC9BQ,OAAO;MACX;AAEA,aAAO,IAAIC,OACP,IAAIC,WAAWZ,UAAAA,GACf,OAAOa,UAAUC,SAAS,MAAMjB,KAAKgB,UAAUC,IAAAA,CAAAA;IAEvD,CAAA;EACJ;EAEAC,OAAQ;EAIR;AACJ;","names":["Mailable","toAddress","ccAddresses","bccAddresses","subjectText","htmlContent","textContent","viewPath","viewData","attachmentsList","to","address","cc","addresses","bcc","subject","html","text","view","path","data","attach","filename","filePath","push","getMessageOptions","attachments","Mailer","driver","edgeRenderer","send","mailable","build","options","getMessageOptions","viewPath","html","viewData","SMTPDriver","transporter","config","nodemailer","createTransport","host","port","secure","auth","user","pass","send","options","sendMail","to","cc","bcc","subject","html","text","attachments","MailServiceProvider","ServiceProvider","priority","register","app","singleton","view","make","config","smtpConfig","host","get","port","Number","auth","user","pass","opportunisticTLS","connectionTimeout","debug","Mailer","SMTPDriver","viewPath","data","boot"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,17 +1,77 @@
|
|
|
1
|
+
import { SendMailOptions as SendMailOptions$1 } from 'nodemailer';
|
|
2
|
+
import SMTPConnection from 'nodemailer/lib/smtp-connection';
|
|
3
|
+
import * as nodemailer_lib_smtp_transport from 'nodemailer/lib/smtp-transport';
|
|
1
4
|
import { ServiceProvider } from '@h3ravel/core';
|
|
2
5
|
|
|
6
|
+
interface SendMailOptions extends SendMailOptions$1 {
|
|
7
|
+
viewPath?: string;
|
|
8
|
+
viewData?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
interface SMTPConfig extends SMTPConnection.Options {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
auth: {
|
|
14
|
+
user: string;
|
|
15
|
+
pass: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface MailDriverContract {
|
|
19
|
+
send(options: SendMailOptions$1): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare abstract class Mailable {
|
|
23
|
+
protected toAddress?: string;
|
|
24
|
+
protected ccAddresses?: string[];
|
|
25
|
+
protected bccAddresses?: string[];
|
|
26
|
+
protected subjectText?: string;
|
|
27
|
+
protected htmlContent?: string;
|
|
28
|
+
protected textContent?: string;
|
|
29
|
+
protected viewPath?: string;
|
|
30
|
+
protected viewData?: Record<string, any>;
|
|
31
|
+
protected attachmentsList?: SendMailOptions['attachments'];
|
|
32
|
+
to(address: string): this;
|
|
33
|
+
cc(...addresses: string[]): this;
|
|
34
|
+
bcc(...addresses: string[]): this;
|
|
35
|
+
subject(subject: string): this;
|
|
36
|
+
html(html: string): this;
|
|
37
|
+
text(text: string): this;
|
|
38
|
+
view(path: string, data?: Record<string, any>): this;
|
|
39
|
+
attach(filename: string, filePath: string): this;
|
|
40
|
+
/**
|
|
41
|
+
* Child classes should define build() like in Laravel
|
|
42
|
+
*/
|
|
43
|
+
abstract build(): Promise<this> | this;
|
|
44
|
+
/**
|
|
45
|
+
* Called internally by Mailer
|
|
46
|
+
*/
|
|
47
|
+
getMessageOptions(): SendMailOptions;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class Mailer {
|
|
51
|
+
private driver;
|
|
52
|
+
private edgeRenderer;
|
|
53
|
+
constructor(driver: MailDriverContract, edgeRenderer: (viewPath: string, data: Record<string, any>) => Promise<string>);
|
|
54
|
+
send(mailable: Mailable): Promise<any>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare class SMTPDriver implements MailDriverContract {
|
|
58
|
+
private transporter;
|
|
59
|
+
constructor(config: SMTPConfig);
|
|
60
|
+
send(options: SendMailOptions$1): Promise<nodemailer_lib_smtp_transport.SentMessageInfo>;
|
|
61
|
+
}
|
|
62
|
+
|
|
3
63
|
/**
|
|
4
64
|
* Mail delivery setup.
|
|
5
65
|
*
|
|
6
66
|
* Bind Mailer service.
|
|
7
|
-
* Load mail drivers (SMTP, SES).
|
|
67
|
+
* Load mail drivers (SMTP, SES, etc.).
|
|
8
68
|
* Register Mail facade.
|
|
9
69
|
*
|
|
10
|
-
* Auto-Registered if @h3ravel/mail is installed
|
|
11
70
|
*/
|
|
12
71
|
declare class MailServiceProvider extends ServiceProvider {
|
|
13
72
|
static priority: number;
|
|
14
73
|
register(): void;
|
|
74
|
+
boot(): void;
|
|
15
75
|
}
|
|
16
76
|
|
|
17
|
-
export { MailServiceProvider };
|
|
77
|
+
export { type MailDriverContract, MailServiceProvider, Mailable, Mailer, type SMTPConfig, SMTPDriver, type SendMailOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,77 @@
|
|
|
1
|
+
import { SendMailOptions as SendMailOptions$1 } from 'nodemailer';
|
|
2
|
+
import SMTPConnection from 'nodemailer/lib/smtp-connection';
|
|
3
|
+
import * as nodemailer_lib_smtp_transport from 'nodemailer/lib/smtp-transport';
|
|
1
4
|
import { ServiceProvider } from '@h3ravel/core';
|
|
2
5
|
|
|
6
|
+
interface SendMailOptions extends SendMailOptions$1 {
|
|
7
|
+
viewPath?: string;
|
|
8
|
+
viewData?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
interface SMTPConfig extends SMTPConnection.Options {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
auth: {
|
|
14
|
+
user: string;
|
|
15
|
+
pass: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface MailDriverContract {
|
|
19
|
+
send(options: SendMailOptions$1): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare abstract class Mailable {
|
|
23
|
+
protected toAddress?: string;
|
|
24
|
+
protected ccAddresses?: string[];
|
|
25
|
+
protected bccAddresses?: string[];
|
|
26
|
+
protected subjectText?: string;
|
|
27
|
+
protected htmlContent?: string;
|
|
28
|
+
protected textContent?: string;
|
|
29
|
+
protected viewPath?: string;
|
|
30
|
+
protected viewData?: Record<string, any>;
|
|
31
|
+
protected attachmentsList?: SendMailOptions['attachments'];
|
|
32
|
+
to(address: string): this;
|
|
33
|
+
cc(...addresses: string[]): this;
|
|
34
|
+
bcc(...addresses: string[]): this;
|
|
35
|
+
subject(subject: string): this;
|
|
36
|
+
html(html: string): this;
|
|
37
|
+
text(text: string): this;
|
|
38
|
+
view(path: string, data?: Record<string, any>): this;
|
|
39
|
+
attach(filename: string, filePath: string): this;
|
|
40
|
+
/**
|
|
41
|
+
* Child classes should define build() like in Laravel
|
|
42
|
+
*/
|
|
43
|
+
abstract build(): Promise<this> | this;
|
|
44
|
+
/**
|
|
45
|
+
* Called internally by Mailer
|
|
46
|
+
*/
|
|
47
|
+
getMessageOptions(): SendMailOptions;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class Mailer {
|
|
51
|
+
private driver;
|
|
52
|
+
private edgeRenderer;
|
|
53
|
+
constructor(driver: MailDriverContract, edgeRenderer: (viewPath: string, data: Record<string, any>) => Promise<string>);
|
|
54
|
+
send(mailable: Mailable): Promise<any>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare class SMTPDriver implements MailDriverContract {
|
|
58
|
+
private transporter;
|
|
59
|
+
constructor(config: SMTPConfig);
|
|
60
|
+
send(options: SendMailOptions$1): Promise<nodemailer_lib_smtp_transport.SentMessageInfo>;
|
|
61
|
+
}
|
|
62
|
+
|
|
3
63
|
/**
|
|
4
64
|
* Mail delivery setup.
|
|
5
65
|
*
|
|
6
66
|
* Bind Mailer service.
|
|
7
|
-
* Load mail drivers (SMTP, SES).
|
|
67
|
+
* Load mail drivers (SMTP, SES, etc.).
|
|
8
68
|
* Register Mail facade.
|
|
9
69
|
*
|
|
10
|
-
* Auto-Registered if @h3ravel/mail is installed
|
|
11
70
|
*/
|
|
12
71
|
declare class MailServiceProvider extends ServiceProvider {
|
|
13
72
|
static priority: number;
|
|
14
73
|
register(): void;
|
|
74
|
+
boot(): void;
|
|
15
75
|
}
|
|
16
76
|
|
|
17
|
-
export { MailServiceProvider };
|
|
77
|
+
export { type MailDriverContract, MailServiceProvider, Mailable, Mailer, type SMTPConfig, SMTPDriver, type SendMailOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,128 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// src/Mailable.ts
|
|
5
|
+
var Mailable = class {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "Mailable");
|
|
8
|
+
}
|
|
9
|
+
toAddress;
|
|
10
|
+
ccAddresses;
|
|
11
|
+
bccAddresses;
|
|
12
|
+
subjectText;
|
|
13
|
+
htmlContent;
|
|
14
|
+
textContent;
|
|
15
|
+
viewPath;
|
|
16
|
+
viewData;
|
|
17
|
+
attachmentsList;
|
|
18
|
+
to(address) {
|
|
19
|
+
this.toAddress = address;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
cc(...addresses) {
|
|
23
|
+
this.ccAddresses = addresses;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
bcc(...addresses) {
|
|
27
|
+
this.bccAddresses = addresses;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
subject(subject) {
|
|
31
|
+
this.subjectText = subject;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
html(html) {
|
|
35
|
+
this.htmlContent = html;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
text(text) {
|
|
39
|
+
this.textContent = text;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
view(path, data = {}) {
|
|
43
|
+
this.viewPath = path;
|
|
44
|
+
this.viewData = data;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
attach(filename, filePath) {
|
|
48
|
+
if (!this.attachmentsList)
|
|
49
|
+
this.attachmentsList = [];
|
|
50
|
+
this.attachmentsList.push({
|
|
51
|
+
filename,
|
|
52
|
+
path: filePath
|
|
53
|
+
});
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Called internally by Mailer
|
|
58
|
+
*/
|
|
59
|
+
getMessageOptions() {
|
|
60
|
+
return {
|
|
61
|
+
to: this.toAddress,
|
|
62
|
+
cc: this.ccAddresses,
|
|
63
|
+
bcc: this.bccAddresses,
|
|
64
|
+
subject: this.subjectText,
|
|
65
|
+
html: this.htmlContent,
|
|
66
|
+
text: this.textContent,
|
|
67
|
+
viewPath: this.viewPath,
|
|
68
|
+
viewData: this.viewData,
|
|
69
|
+
attachments: this.attachmentsList
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/Mailer.ts
|
|
75
|
+
var Mailer = class {
|
|
76
|
+
static {
|
|
77
|
+
__name(this, "Mailer");
|
|
78
|
+
}
|
|
79
|
+
driver;
|
|
80
|
+
edgeRenderer;
|
|
81
|
+
constructor(driver, edgeRenderer) {
|
|
82
|
+
this.driver = driver;
|
|
83
|
+
this.edgeRenderer = edgeRenderer;
|
|
84
|
+
}
|
|
85
|
+
async send(mailable) {
|
|
86
|
+
await mailable.build();
|
|
87
|
+
const options = mailable.getMessageOptions();
|
|
88
|
+
if (options.viewPath && !options.html) {
|
|
89
|
+
options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
|
|
90
|
+
}
|
|
91
|
+
return this.driver.send(options);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/Drivers/SMTPDriver.ts
|
|
96
|
+
import nodemailer from "nodemailer";
|
|
97
|
+
var SMTPDriver = class {
|
|
98
|
+
static {
|
|
99
|
+
__name(this, "SMTPDriver");
|
|
100
|
+
}
|
|
101
|
+
transporter;
|
|
102
|
+
constructor(config) {
|
|
103
|
+
this.transporter = nodemailer.createTransport({
|
|
104
|
+
host: config.host,
|
|
105
|
+
port: config.port,
|
|
106
|
+
secure: config.port === 465,
|
|
107
|
+
auth: {
|
|
108
|
+
user: config.auth.user,
|
|
109
|
+
pass: config.auth.pass
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async send(options) {
|
|
114
|
+
return await this.transporter.sendMail({
|
|
115
|
+
to: options.to,
|
|
116
|
+
cc: options.cc,
|
|
117
|
+
bcc: options.bcc,
|
|
118
|
+
subject: options.subject,
|
|
119
|
+
html: options.html,
|
|
120
|
+
text: options.text,
|
|
121
|
+
attachments: options.attachments
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
4
126
|
// src/Providers/MailServiceProvider.ts
|
|
5
127
|
import { ServiceProvider } from "@h3ravel/core";
|
|
6
128
|
var MailServiceProvider = class extends ServiceProvider {
|
|
@@ -9,9 +131,30 @@ var MailServiceProvider = class extends ServiceProvider {
|
|
|
9
131
|
}
|
|
10
132
|
static priority = 990;
|
|
11
133
|
register() {
|
|
134
|
+
this.app.singleton("mailer", () => {
|
|
135
|
+
const view = this.app.make("view");
|
|
136
|
+
const config = this.app.make("config");
|
|
137
|
+
const smtpConfig = {
|
|
138
|
+
host: config.get("mail.mailers.smtp.host", "smtp.mailtrap.io"),
|
|
139
|
+
port: Number(config.get("mail.mailers.smtp.port", 2525)),
|
|
140
|
+
auth: {
|
|
141
|
+
user: config.get("mail.mailers.smtp.username", ""),
|
|
142
|
+
pass: config.get("mail.mailers.smtp.password", "")
|
|
143
|
+
},
|
|
144
|
+
opportunisticTLS: config.get("mail.mailers.smtp.encryption") === "tls",
|
|
145
|
+
connectionTimeout: config.get("mail.mailers.smtp.timeout"),
|
|
146
|
+
debug: false
|
|
147
|
+
};
|
|
148
|
+
return new Mailer(new SMTPDriver(smtpConfig), async (viewPath, data) => await view(viewPath, data));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
boot() {
|
|
12
152
|
}
|
|
13
153
|
};
|
|
14
154
|
export {
|
|
15
|
-
MailServiceProvider
|
|
155
|
+
MailServiceProvider,
|
|
156
|
+
Mailable,
|
|
157
|
+
Mailer,
|
|
158
|
+
SMTPDriver
|
|
16
159
|
};
|
|
17
160
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Providers/MailServiceProvider.ts"],"sourcesContent":["import { ServiceProvider } from '@h3ravel/core'
|
|
1
|
+
{"version":3,"sources":["../src/Mailable.ts","../src/Mailer.ts","../src/Drivers/SMTPDriver.ts","../src/Providers/MailServiceProvider.ts"],"sourcesContent":["import type { SendMailOptions } from \"./Contracts/Mailer\";\n\nexport abstract class Mailable {\n protected toAddress?: string;\n protected ccAddresses?: string[];\n protected bccAddresses?: string[];\n protected subjectText?: string;\n protected htmlContent?: string;\n protected textContent?: string;\n protected viewPath?: string;\n protected viewData?: Record<string, any>;\n protected attachmentsList?: SendMailOptions['attachments'];\n\n to (address: string) {\n this.toAddress = address;\n return this;\n }\n\n cc (...addresses: string[]) {\n this.ccAddresses = addresses;\n return this;\n }\n\n bcc (...addresses: string[]) {\n this.bccAddresses = addresses;\n return this;\n }\n\n subject (subject: string) {\n this.subjectText = subject;\n return this;\n }\n\n html (html: string) {\n this.htmlContent = html;\n return this;\n }\n\n text (text: string) {\n this.textContent = text;\n return this;\n }\n\n view (path: string, data: Record<string, any> = {}) {\n this.viewPath = path;\n this.viewData = data;\n return this;\n }\n\n attach (filename: string, filePath: string) {\n if (!this.attachmentsList) this.attachmentsList = [];\n this.attachmentsList.push({ filename, path: filePath });\n return this;\n }\n\n /**\n * Child classes should define build() like in Laravel\n */\n abstract build (): Promise<this> | this;\n\n /**\n * Called internally by Mailer\n */\n getMessageOptions (): SendMailOptions {\n return {\n to: this.toAddress,\n cc: this.ccAddresses,\n bcc: this.bccAddresses,\n subject: this.subjectText,\n html: this.htmlContent,\n text: this.textContent,\n viewPath: this.viewPath,\n viewData: this.viewData,\n attachments: this.attachmentsList\n };\n }\n}\n","import { MailDriverContract } from './Contracts/Mailer';\nimport { Mailable } from './Mailable';\n\nexport class Mailer {\n constructor(\n private driver: MailDriverContract,\n private edgeRenderer: (viewPath: string, data: Record<string, any>) => Promise<string>\n ) { }\n\n async send (mailable: Mailable) {\n await mailable.build();\n\n const options = mailable.getMessageOptions();\n\n if (options.viewPath && !options.html) {\n options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});\n }\n\n return this.driver.send(options);\n }\n}\n","import nodemailer, { type SendMailOptions, type TransportOptions } from 'nodemailer';\n\nimport { MailDriverContract, SMTPConfig } from '../Contracts/Mailer';\n\nexport class SMTPDriver implements MailDriverContract {\n private transporter;\n\n constructor(config: SMTPConfig) {\n this.transporter = nodemailer.createTransport({\n host: config.host,\n port: config.port,\n secure: config.port === 465, // auto decide based on port\n auth: {\n user: config.auth.user,\n pass: config.auth.pass\n }\n });\n }\n\n async send (options: SendMailOptions) {\n return await this.transporter.sendMail({\n to: options.to,\n cc: options.cc,\n bcc: options.bcc,\n subject: options.subject,\n html: options.html,\n text: options.text,\n attachments: options.attachments\n });\n }\n}\n","import { Mailer } from '../Mailer';\nimport { SMTPConfig } from '../Contracts/Mailer';\nimport { SMTPDriver } from '../Drivers/SMTPDriver';\nimport { ServiceProvider } from '@h3ravel/core';\n\n/**\n * Mail delivery setup.\n * \n * Bind Mailer service.\n * Load mail drivers (SMTP, SES, etc.).\n * Register Mail facade.\n * \n */\nexport class MailServiceProvider extends ServiceProvider {\n public static priority = 990;\n register () {\n /**\n * Register Mailer instance\n */\n\n this.app.singleton<any>('mailer', () => {\n // this.app.bind(Mailer, () => {\n const view = this.app.make('view');\n const config = this.app.make('config');\n\n const smtpConfig: SMTPConfig = {\n host: config.get('mail.mailers.smtp.host', 'smtp.mailtrap.io'),\n port: Number(config.get('mail.mailers.smtp.port', 2525)),\n auth: {\n user: config.get('mail.mailers.smtp.username', ''),\n pass: config.get('mail.mailers.smtp.password', ''),\n },\n opportunisticTLS: config.get('mail.mailers.smtp.encryption') === 'tls',\n connectionTimeout: config.get('mail.mailers.smtp.timeout'),\n debug: false,\n };\n\n return new Mailer(\n new SMTPDriver(smtpConfig),\n async (viewPath, data) => await view(viewPath, data)\n );\n });\n }\n\n boot () {\n /**\n * Add logic here for global mail \"from\" address and others\n */\n }\n}\n"],"mappings":";;;;AAEO,IAAeA,WAAf,MAAeA;EAAtB,OAAsBA;;;EACRC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EAEVC,GAAIC,SAAiB;AACjB,SAAKV,YAAYU;AACjB,WAAO;EACX;EAEAC,MAAOC,WAAqB;AACxB,SAAKX,cAAcW;AACnB,WAAO;EACX;EAEAC,OAAQD,WAAqB;AACzB,SAAKV,eAAeU;AACpB,WAAO;EACX;EAEAE,QAASA,SAAiB;AACtB,SAAKX,cAAcW;AACnB,WAAO;EACX;EAEAC,KAAMA,MAAc;AAChB,SAAKX,cAAcW;AACnB,WAAO;EACX;EAEAC,KAAMA,MAAc;AAChB,SAAKX,cAAcW;AACnB,WAAO;EACX;EAEAC,KAAMC,MAAcC,OAA4B,CAAC,GAAG;AAChD,SAAKb,WAAWY;AAChB,SAAKX,WAAWY;AAChB,WAAO;EACX;EAEAC,OAAQC,UAAkBC,UAAkB;AACxC,QAAI,CAAC,KAAKd;AAAiB,WAAKA,kBAAkB,CAAA;AAClD,SAAKA,gBAAgBe,KAAK;MAAEF;MAAUH,MAAMI;IAAS,CAAA;AACrD,WAAO;EACX;;;;EAUAE,oBAAsC;AAClC,WAAO;MACHf,IAAI,KAAKT;MACTW,IAAI,KAAKV;MACTY,KAAK,KAAKX;MACVY,SAAS,KAAKX;MACdY,MAAM,KAAKX;MACXY,MAAM,KAAKX;MACXC,UAAU,KAAKA;MACfC,UAAU,KAAKA;MACfkB,aAAa,KAAKjB;IACtB;EACJ;AACJ;;;ACzEO,IAAMkB,SAAN,MAAMA;EAAb,OAAaA;;;;;EACT,YACYC,QACAC,cACV;SAFUD,SAAAA;SACAC,eAAAA;EACR;EAEJ,MAAMC,KAAMC,UAAoB;AAC5B,UAAMA,SAASC,MAAK;AAEpB,UAAMC,UAAUF,SAASG,kBAAiB;AAE1C,QAAID,QAAQE,YA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G,IAAI,2BAAA;QAC9BQ,OAAO;MACX;AAEA,aAAO,IAAIC,OACP,IAAIC,WAAWZ,UAAAA,GACf,OAAOa,UAAUC,SAAS,MAAMjB,KAAKgB,UAAUC,IAAAA,CAAAA;IAEvD,CAAA;EACJ;EAEAC,OAAQ;EAIR;AACJ;","names":["Mailable","toAddress","ccAddresses","bccAddresses","subjectText","htmlContent","textContent","viewPath","viewData","attachmentsList","to","address","cc","addresses","bcc","subject","html","text","view","path","data","attach","filename","filePath","push","getMessageOptions","attachments","Mailer","driver","edgeRenderer","send","mailable","build","options","getMessageOptions","viewPath","html","viewData","nodemailer","SMTPDriver","transporter","config","nodemailer","createTransport","host","port","secure","auth","user","pass","send","options","sendMail","to","cc","bcc","subject","html","text","attachments","ServiceProvider","MailServiceProvider","ServiceProvider","priority","register","app","singleton","view","make","config","smtpConfig","host","get","port","Number","auth","user","pass","opportunisticTLS","connectionTimeout","debug","Mailer","SMTPDriver","viewPath","data","boot"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/mail",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Mail drivers and templates system for H3ravel.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
8
16
|
"publishConfig": {
|
|
9
17
|
"access": "public"
|
|
10
18
|
},
|
|
@@ -15,11 +23,15 @@
|
|
|
15
23
|
"directory": "packages/mail"
|
|
16
24
|
},
|
|
17
25
|
"peerDependencies": {
|
|
18
|
-
"@h3ravel/core": "^1.
|
|
26
|
+
"@h3ravel/core": "^1.4.0"
|
|
19
27
|
},
|
|
20
28
|
"devDependencies": {
|
|
29
|
+
"@types/nodemailer": "^6.4.17",
|
|
21
30
|
"typescript": "^5.4.0"
|
|
22
31
|
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"nodemailer": "^7.0.5"
|
|
34
|
+
},
|
|
23
35
|
"scripts": {
|
|
24
36
|
"barrel": "barrelsby --directory src --delete --singleQuotes",
|
|
25
37
|
"build": "tsup",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SendMailOptions as NodeMailerSendMailOptions } from "nodemailer";
|
|
2
|
+
import SMTPConnection from "nodemailer/lib/smtp-connection";
|
|
3
|
+
|
|
4
|
+
export interface SendMailOptions extends NodeMailerSendMailOptions {
|
|
5
|
+
viewPath?: string,
|
|
6
|
+
viewData?: Record<string, any>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SMTPConfig extends SMTPConnection.Options {
|
|
10
|
+
host: string;
|
|
11
|
+
port: number;
|
|
12
|
+
auth: {
|
|
13
|
+
user: string;
|
|
14
|
+
pass: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MailDriverContract {
|
|
19
|
+
send (options: NodeMailerSendMailOptions): Promise<any>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import nodemailer, { type SendMailOptions, type TransportOptions } from 'nodemailer';
|
|
2
|
+
|
|
3
|
+
import { MailDriverContract, SMTPConfig } from '../Contracts/Mailer';
|
|
4
|
+
|
|
5
|
+
export class SMTPDriver implements MailDriverContract {
|
|
6
|
+
private transporter;
|
|
7
|
+
|
|
8
|
+
constructor(config: SMTPConfig) {
|
|
9
|
+
this.transporter = nodemailer.createTransport({
|
|
10
|
+
host: config.host,
|
|
11
|
+
port: config.port,
|
|
12
|
+
secure: config.port === 465, // auto decide based on port
|
|
13
|
+
auth: {
|
|
14
|
+
user: config.auth.user,
|
|
15
|
+
pass: config.auth.pass
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async send (options: SendMailOptions) {
|
|
21
|
+
return await this.transporter.sendMail({
|
|
22
|
+
to: options.to,
|
|
23
|
+
cc: options.cc,
|
|
24
|
+
bcc: options.bcc,
|
|
25
|
+
subject: options.subject,
|
|
26
|
+
html: options.html,
|
|
27
|
+
text: options.text,
|
|
28
|
+
attachments: options.attachments
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/Mailable.ts
CHANGED
|
@@ -1 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
import type { SendMailOptions } from "./Contracts/Mailer";
|
|
2
|
+
|
|
3
|
+
export abstract class Mailable {
|
|
4
|
+
protected toAddress?: string;
|
|
5
|
+
protected ccAddresses?: string[];
|
|
6
|
+
protected bccAddresses?: string[];
|
|
7
|
+
protected subjectText?: string;
|
|
8
|
+
protected htmlContent?: string;
|
|
9
|
+
protected textContent?: string;
|
|
10
|
+
protected viewPath?: string;
|
|
11
|
+
protected viewData?: Record<string, any>;
|
|
12
|
+
protected attachmentsList?: SendMailOptions['attachments'];
|
|
13
|
+
|
|
14
|
+
to (address: string) {
|
|
15
|
+
this.toAddress = address;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
cc (...addresses: string[]) {
|
|
20
|
+
this.ccAddresses = addresses;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
bcc (...addresses: string[]) {
|
|
25
|
+
this.bccAddresses = addresses;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
subject (subject: string) {
|
|
30
|
+
this.subjectText = subject;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
html (html: string) {
|
|
35
|
+
this.htmlContent = html;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
text (text: string) {
|
|
40
|
+
this.textContent = text;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
view (path: string, data: Record<string, any> = {}) {
|
|
45
|
+
this.viewPath = path;
|
|
46
|
+
this.viewData = data;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
attach (filename: string, filePath: string) {
|
|
51
|
+
if (!this.attachmentsList) this.attachmentsList = [];
|
|
52
|
+
this.attachmentsList.push({ filename, path: filePath });
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Child classes should define build() like in Laravel
|
|
58
|
+
*/
|
|
59
|
+
abstract build (): Promise<this> | this;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Called internally by Mailer
|
|
63
|
+
*/
|
|
64
|
+
getMessageOptions (): SendMailOptions {
|
|
65
|
+
return {
|
|
66
|
+
to: this.toAddress,
|
|
67
|
+
cc: this.ccAddresses,
|
|
68
|
+
bcc: this.bccAddresses,
|
|
69
|
+
subject: this.subjectText,
|
|
70
|
+
html: this.htmlContent,
|
|
71
|
+
text: this.textContent,
|
|
72
|
+
viewPath: this.viewPath,
|
|
73
|
+
viewData: this.viewData,
|
|
74
|
+
attachments: this.attachmentsList
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/Mailer.ts
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { MailDriverContract } from './Contracts/Mailer';
|
|
2
|
+
import { Mailable } from './Mailable';
|
|
3
|
+
|
|
4
|
+
export class Mailer {
|
|
5
|
+
constructor(
|
|
6
|
+
private driver: MailDriverContract,
|
|
7
|
+
private edgeRenderer: (viewPath: string, data: Record<string, any>) => Promise<string>
|
|
8
|
+
) { }
|
|
9
|
+
|
|
10
|
+
async send (mailable: Mailable) {
|
|
11
|
+
await mailable.build();
|
|
12
|
+
|
|
13
|
+
const options = mailable.getMessageOptions();
|
|
14
|
+
|
|
15
|
+
if (options.viewPath && !options.html) {
|
|
16
|
+
options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return this.driver.send(options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,18 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Mailer } from '../Mailer';
|
|
2
|
+
import { SMTPConfig } from '../Contracts/Mailer';
|
|
3
|
+
import { SMTPDriver } from '../Drivers/SMTPDriver';
|
|
4
|
+
import { ServiceProvider } from '@h3ravel/core';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Mail delivery setup.
|
|
5
8
|
*
|
|
6
9
|
* Bind Mailer service.
|
|
7
|
-
* Load mail drivers (SMTP, SES).
|
|
10
|
+
* Load mail drivers (SMTP, SES, etc.).
|
|
8
11
|
* Register Mail facade.
|
|
9
12
|
*
|
|
10
|
-
* Auto-Registered if @h3ravel/mail is installed
|
|
11
13
|
*/
|
|
12
14
|
export class MailServiceProvider extends ServiceProvider {
|
|
13
15
|
public static priority = 990;
|
|
14
|
-
|
|
15
16
|
register () {
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Register Mailer instance
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
this.app.singleton<any>('mailer', () => {
|
|
22
|
+
// this.app.bind(Mailer, () => {
|
|
23
|
+
const view = this.app.make('view');
|
|
24
|
+
const config = this.app.make('config');
|
|
25
|
+
|
|
26
|
+
const smtpConfig: SMTPConfig = {
|
|
27
|
+
host: config.get('mail.mailers.smtp.host', 'smtp.mailtrap.io'),
|
|
28
|
+
port: Number(config.get('mail.mailers.smtp.port', 2525)),
|
|
29
|
+
auth: {
|
|
30
|
+
user: config.get('mail.mailers.smtp.username', ''),
|
|
31
|
+
pass: config.get('mail.mailers.smtp.password', ''),
|
|
32
|
+
},
|
|
33
|
+
opportunisticTLS: config.get('mail.mailers.smtp.encryption') === 'tls',
|
|
34
|
+
connectionTimeout: config.get('mail.mailers.smtp.timeout'),
|
|
35
|
+
debug: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return new Mailer(
|
|
39
|
+
new SMTPDriver(smtpConfig),
|
|
40
|
+
async (viewPath, data) => await view(viewPath, data)
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
boot () {
|
|
46
|
+
/**
|
|
47
|
+
* Add logic here for global mail "from" address and others
|
|
48
|
+
*/
|
|
17
49
|
}
|
|
18
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export * from './Helpers';
|
|
6
6
|
export * from './Mailable';
|
|
7
7
|
export * from './Mailer';
|
|
8
|
+
export * from './Contracts/Mailer';
|
|
8
9
|
export * from './Drivers/SES';
|
|
9
|
-
export * from './Drivers/
|
|
10
|
+
export * from './Drivers/SMTPDriver';
|
|
10
11
|
export * from './Providers/MailServiceProvider';
|
package/src/Contracts/.gitkeep
DELETED
|
File without changes
|
package/src/Drivers/SMTP.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default class { }
|