@creator.co/wapi 1.1.4 → 1.1.5
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.
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import * as Email from "email-templates";
|
|
1
2
|
export default class Mailer {
|
|
2
3
|
private readonly from;
|
|
3
4
|
private readonly templateDefaultFile;
|
|
4
5
|
private readonly transporter;
|
|
5
6
|
constructor(defaultFrom: string, region: string);
|
|
6
|
-
sendRawEmail(to: string | Array<string>, htmlMessage: string, subject: string, optionalCC?: string | Array<string>, optionalFrom?: string, optionalAttachments?: any[]): Promise<any>;
|
|
7
|
-
sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: string, optionalAttachments?: any[]): Promise<any>;
|
|
7
|
+
sendRawEmail(to: string | Array<string>, htmlMessage: string, subject: string, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<any>;
|
|
8
|
+
sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<any>;
|
|
9
|
+
newSMTPTransporter(host: string, portNumber: number, user: string, password: string): Email.NodeMailerTransportOptions;
|
|
8
10
|
private chooseTemplate;
|
|
9
11
|
private canRenderTemplate;
|
|
10
12
|
}
|
|
@@ -66,17 +66,17 @@ var Mailer = /** @class */ (function () {
|
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
Mailer.prototype.sendRawEmail = function (to, htmlMessage, subject, optionalCC, optionalFrom,
|
|
69
|
+
Mailer.prototype.sendRawEmail = function (to, htmlMessage, subject, optionalCC, optionalFrom, optionalReplyTo,
|
|
70
70
|
// TODO: improve attachment type -> Attachment
|
|
71
|
-
optionalAttachments) {
|
|
71
|
+
optionalAttachments, optionalTransport) {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
73
73
|
var email, resp, e_1;
|
|
74
74
|
return __generator(this, function (_a) {
|
|
75
75
|
switch (_a.label) {
|
|
76
76
|
case 0:
|
|
77
77
|
email = new Email({
|
|
78
|
-
message: __assign(__assign({ from: optionalFrom || this.from, to: to, html: htmlMessage, subject: subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})),
|
|
79
|
-
transport: this.transporter,
|
|
78
|
+
message: __assign(__assign(__assign({ from: optionalFrom || this.from, to: to, html: htmlMessage, subject: subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
|
|
79
|
+
transport: optionalTransport || this.transporter,
|
|
80
80
|
send: true,
|
|
81
81
|
});
|
|
82
82
|
resp = null;
|
|
@@ -97,17 +97,17 @@ var Mailer = /** @class */ (function () {
|
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
|
-
Mailer.prototype.sendTemplatedEmail = function (to, templates, data, optionalCC, optionalFrom,
|
|
100
|
+
Mailer.prototype.sendTemplatedEmail = function (to, templates, data, optionalCC, optionalFrom, optionalReplyTo,
|
|
101
101
|
// TODO: improve attachment type -> Attachment
|
|
102
|
-
optionalAttachments) {
|
|
102
|
+
optionalAttachments, optionalTransport) {
|
|
103
103
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
104
|
var email, resp, chosenTemplate, e_2;
|
|
105
105
|
return __generator(this, function (_a) {
|
|
106
106
|
switch (_a.label) {
|
|
107
107
|
case 0:
|
|
108
108
|
email = new Email({
|
|
109
|
-
message: __assign(__assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})),
|
|
110
|
-
transport: this.transporter,
|
|
109
|
+
message: __assign(__assign(__assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
|
|
110
|
+
transport: optionalTransport || this.transporter,
|
|
111
111
|
send: true,
|
|
112
112
|
});
|
|
113
113
|
resp = null;
|
|
@@ -131,6 +131,18 @@ var Mailer = /** @class */ (function () {
|
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
|
+
Mailer.prototype.newSMTPTransporter = function (host, portNumber, user, password) {
|
|
135
|
+
var smtpTransporter = nodemailer.createTransport({
|
|
136
|
+
host: host,
|
|
137
|
+
port: portNumber,
|
|
138
|
+
connectionTimeout: 2000,
|
|
139
|
+
auth: {
|
|
140
|
+
user: user,
|
|
141
|
+
pass: password,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return smtpTransporter;
|
|
145
|
+
};
|
|
134
146
|
/* private */
|
|
135
147
|
Mailer.prototype.chooseTemplate = function (templates, data) {
|
|
136
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../../src/Mailer/Mailer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0C;AAC1C,8EAAmE;AACnE,uCAAwC;AACxC,uCAAwC;AAGxC;IAME,gBAAY,WAAmB,EAAE,MAAc;QAJ9B,wBAAmB,GAAW,MAAM,CAAA;QAKnD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;YAC5C,GAAG,EAAE;gBACH,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,CAAC;oBACrB,WAAW,EAAE,IAAA,0CAAe,GAAE;oBAC9B,UAAU,EAAE,YAAY;oBACxB,MAAM,QAAA;iBACP,CAAC;gBACF,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AAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAChC,CAAA;;;;KACF;IACa,kCAAiB,GAA/B,UACE,QAAgB,EAChB,IAAY;;;;;;wBAER,eAAe,GAAG,IAAI,CAAA;;;;wBAElB,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;wBACP,qBAAM,KAAK,CAAC,MAAM,CAClC,UAAG,QAAQ,cAAI,IAAI,CAAC,mBAAmB,CAAE,EACzC,IAAI,CACL,EAAA;;wBAHD,eAAe,GAAG,SAGjB,CAAA;;;;wBAED,OAAO,CAAC,GAAG,CACT,+DAAwD,QAAQ,CAAE,EAClE,GAAC,CACF,CAAA;;4BAEH,sBAAO,eAAe,IAAI,IAAI,EAAA;;;;KAC/B;IACH,aAAC;AAAD,CAAC,AAhJD,IAgJC"}
|
package/package.json
CHANGED
package/src/Mailer/Mailer.ts
CHANGED
|
@@ -30,8 +30,10 @@ export default class Mailer {
|
|
|
30
30
|
subject: string,
|
|
31
31
|
optionalCC?: string | Array<string>,
|
|
32
32
|
optionalFrom?: string,
|
|
33
|
+
optionalReplyTo?: string,
|
|
33
34
|
// TODO: improve attachment type -> Attachment
|
|
34
35
|
optionalAttachments?: any[],
|
|
36
|
+
optionalTransport?: Email.NodeMailerTransportOptions,
|
|
35
37
|
) {
|
|
36
38
|
//Generate emails
|
|
37
39
|
const email = new Email({
|
|
@@ -42,8 +44,9 @@ export default class Mailer {
|
|
|
42
44
|
subject,
|
|
43
45
|
...(optionalAttachments ? { attachments: optionalAttachments } : {}),
|
|
44
46
|
...(optionalCC ? { cc: optionalCC } : {}),
|
|
47
|
+
...(optionalReplyTo ? { replyTo: optionalReplyTo } : {}),
|
|
45
48
|
},
|
|
46
|
-
transport: this.transporter,
|
|
49
|
+
transport: optionalTransport || this.transporter,
|
|
47
50
|
send: true,
|
|
48
51
|
})
|
|
49
52
|
//
|
|
@@ -62,8 +65,10 @@ export default class Mailer {
|
|
|
62
65
|
data: object,
|
|
63
66
|
optionalCC?: string | Array<string>,
|
|
64
67
|
optionalFrom?: string,
|
|
68
|
+
optionalReplyTo?: string,
|
|
65
69
|
// TODO: improve attachment type -> Attachment
|
|
66
70
|
optionalAttachments?: any[],
|
|
71
|
+
optionalTransport?: Email.NodeMailerTransportOptions,
|
|
67
72
|
) {
|
|
68
73
|
//Generate emails
|
|
69
74
|
const email = new Email({
|
|
@@ -72,8 +77,9 @@ export default class Mailer {
|
|
|
72
77
|
to: to,
|
|
73
78
|
...(optionalAttachments ? { attachments: optionalAttachments } : {}),
|
|
74
79
|
...(optionalCC ? { cc: optionalCC } : {}),
|
|
80
|
+
...(optionalReplyTo ? { replyTo: optionalReplyTo } : {}),
|
|
75
81
|
},
|
|
76
|
-
transport: this.transporter,
|
|
82
|
+
transport: optionalTransport || this.transporter,
|
|
77
83
|
send: true,
|
|
78
84
|
})
|
|
79
85
|
//
|
|
@@ -87,6 +93,23 @@ export default class Mailer {
|
|
|
87
93
|
}
|
|
88
94
|
return resp
|
|
89
95
|
}
|
|
96
|
+
public newSMTPTransporter(
|
|
97
|
+
host: string,
|
|
98
|
+
portNumber: number,
|
|
99
|
+
user: string,
|
|
100
|
+
password: string,
|
|
101
|
+
): Email.NodeMailerTransportOptions {
|
|
102
|
+
const smtpTransporter = nodemailer.createTransport({
|
|
103
|
+
host: host,
|
|
104
|
+
port: portNumber,
|
|
105
|
+
connectionTimeout: 2000,
|
|
106
|
+
auth: {
|
|
107
|
+
user: user,
|
|
108
|
+
pass: password,
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
return smtpTransporter
|
|
112
|
+
}
|
|
90
113
|
|
|
91
114
|
/* private */
|
|
92
115
|
private async chooseTemplate(
|