namirasoft-node 1.3.15 → 1.3.17

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.
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { AttachmentLike } from "nodemailer/lib/mailer";
4
+ import { Readable } from "stream";
5
+ export declare abstract class BaseEmailService {
6
+ username: string;
7
+ constructor(username: string);
8
+ protected abstract getTransform(): any;
9
+ send(from: string | null, to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void): void;
10
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BaseEmailService = void 0;
7
+ const nodemailer_1 = __importDefault(require("nodemailer"));
8
+ class BaseEmailService {
9
+ constructor(username) {
10
+ this.username = username;
11
+ }
12
+ send(from, to, subject, text, html, callback) {
13
+ let transform = this.getTransform();
14
+ let transporter = nodemailer_1.default.createTransport(transform);
15
+ let mailOptions = {
16
+ from: from !== null && from !== void 0 ? from : this.username,
17
+ to,
18
+ subject,
19
+ text,
20
+ html
21
+ };
22
+ if (html)
23
+ mailOptions.html = html;
24
+ transporter.sendMail(mailOptions, function (error, info) {
25
+ if (callback)
26
+ callback(error, info);
27
+ else {
28
+ if (error)
29
+ console.log(error);
30
+ }
31
+ });
32
+ }
33
+ }
34
+ exports.BaseEmailService = BaseEmailService;
35
+ //# sourceMappingURL=BaseEmailService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseEmailService.js","sourceRoot":"","sources":["../src/BaseEmailService.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AAIpC,MAAsB,gBAAgB;IAGlC,YAAY,QAAgB;QAExB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,IAAmB,EAAE,EAAU,EAAE,OAAe,EAAE,IAAY,EAAE,IAA8D,EAAE,QAAiD;QAElL,IAAI,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACpC,IAAI,WAAW,GAAG,oBAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAExD,IAAI,WAAW,GAAiB;YAC5B,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC,QAAQ;YAC3B,EAAE;YACF,OAAO;YACP,IAAI;YACJ,IAAI;SACP,CAAC;QACF,IAAI,IAAI;YACJ,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;QAE5B,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,UAAU,KAAK,EAAE,IAAI;YAEnD,IAAI,QAAQ;gBACR,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAE1B;gBACI,IAAI,KAAK;oBACL,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aAC1B;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAlCD,4CAkCC"}
@@ -0,0 +1,6 @@
1
+ import { BaseEmailService } from './BaseEmailService';
2
+ export declare class Gmail extends BaseEmailService {
3
+ password: string;
4
+ constructor(username: string, password: string);
5
+ protected getTransform(): any;
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Gmail = void 0;
7
+ const nodemailer_smtp_transport_1 = __importDefault(require("nodemailer-smtp-transport"));
8
+ const BaseEmailService_1 = require("./BaseEmailService");
9
+ class Gmail extends BaseEmailService_1.BaseEmailService {
10
+ constructor(username, password) {
11
+ super(username);
12
+ this.password = password;
13
+ }
14
+ getTransform() {
15
+ return (0, nodemailer_smtp_transport_1.default)({
16
+ service: 'gmail',
17
+ host: 'smtp.gmail.com',
18
+ auth: {
19
+ user: this.username,
20
+ pass: this.password
21
+ }
22
+ });
23
+ }
24
+ }
25
+ exports.Gmail = Gmail;
26
+ //# sourceMappingURL=GmailService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GmailService.js","sourceRoot":"","sources":["../src/GmailService.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAsD;AACtD,yDAAsD;AAEtD,MAAa,KAAM,SAAQ,mCAAgB;IAGvC,YAAY,QAAgB,EAAE,QAAgB;QAE1C,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IACkB,YAAY;QAE3B,OAAO,IAAA,mCAAa,EAAC;YACjB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE;gBACF,IAAI,EAAE,IAAI,CAAC,QAAQ;gBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;aACtB;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AAnBD,sBAmBC"}
@@ -0,0 +1,8 @@
1
+ import { BaseEmailService } from './BaseEmailService';
2
+ export declare class SMTPService extends BaseEmailService {
3
+ host: string;
4
+ port: number;
5
+ password: string;
6
+ constructor(host: string, username: string, port: number, password: string);
7
+ protected getTransform(): any;
8
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SMTPService = void 0;
4
+ const BaseEmailService_1 = require("./BaseEmailService");
5
+ class SMTPService extends BaseEmailService_1.BaseEmailService {
6
+ constructor(host, username, port, password) {
7
+ super(username);
8
+ this.host = host;
9
+ this.port = port;
10
+ this.password = password;
11
+ }
12
+ getTransform() {
13
+ return {
14
+ host: this.host,
15
+ port: this.port,
16
+ secure: true,
17
+ auth: {
18
+ user: this.username,
19
+ pass: this.password
20
+ }
21
+ };
22
+ }
23
+ }
24
+ exports.SMTPService = SMTPService;
25
+ //# sourceMappingURL=SMTPService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SMTPService.js","sourceRoot":"","sources":["../src/SMTPService.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AAEtD,MAAa,WAAY,SAAQ,mCAAgB;IAK7C,YAAY,IAAY,EAAE,QAAgB,EAAE,IAAY,EAAE,QAAgB;QAEtE,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IACkB,YAAY;QAE3B,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE;gBACF,IAAI,EAAE,IAAI,CAAC,QAAQ;gBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;aACtB;SACJ,CAAC;IACN,CAAC;CACJ;AAxBD,kCAwBC"}
package/dist/index.d.ts CHANGED
@@ -3,12 +3,14 @@ export * from "./BaseApplication";
3
3
  export * from "./BaseApplicationLink";
4
4
  export * from "./BaseController";
5
5
  export * from "./BaseDatabase";
6
+ export * from "./BaseEmailService";
6
7
  export * from "./BaseTable";
7
8
  export * from "./CommandOperation";
8
- export * from "./EmailService";
9
9
  export * from "./EnvService";
10
+ export * from "./GmailService";
10
11
  export * from "./IPOperation";
11
12
  export * from "./Meta";
12
13
  export * from "./OTPOperation";
13
14
  export * from "./RequestHeaderService";
14
15
  export * from "./ServerToServerOperation";
16
+ export * from "./SMTPService";
package/dist/index.js CHANGED
@@ -19,13 +19,15 @@ __exportStar(require("./BaseApplication"), exports);
19
19
  __exportStar(require("./BaseApplicationLink"), exports);
20
20
  __exportStar(require("./BaseController"), exports);
21
21
  __exportStar(require("./BaseDatabase"), exports);
22
+ __exportStar(require("./BaseEmailService"), exports);
22
23
  __exportStar(require("./BaseTable"), exports);
23
24
  __exportStar(require("./CommandOperation"), exports);
24
- __exportStar(require("./EmailService"), exports);
25
25
  __exportStar(require("./EnvService"), exports);
26
+ __exportStar(require("./GmailService"), exports);
26
27
  __exportStar(require("./IPOperation"), exports);
27
28
  __exportStar(require("./Meta"), exports);
28
29
  __exportStar(require("./OTPOperation"), exports);
29
30
  __exportStar(require("./RequestHeaderService"), exports);
30
31
  __exportStar(require("./ServerToServerOperation"), exports);
32
+ __exportStar(require("./SMTPService"), exports);
31
33
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B;AAC5B,qDAAmC;AACnC,iDAA+B;AAC/B,+CAA6B;AAC7B,gDAA8B;AAC9B,yCAAuB;AACvB,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,mDAAiC;AACjC,iDAA+B;AAC/B,qDAAmC;AACnC,8CAA4B;AAC5B,qDAAmC;AACnC,+CAA6B;AAC7B,iDAA+B;AAC/B,gDAA8B;AAC9B,yCAAuB;AACvB,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,gDAA8B"}
package/package.json CHANGED
@@ -8,11 +8,11 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.3.15",
12
- "main": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
11
+ "version": "1.3.17",
14
12
  "author": "Amir Abolhasani",
15
13
  "license": "MIT",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
16
  "scripts": {
17
17
  "build": ""
18
18
  },
@@ -20,7 +20,7 @@
20
20
  "@supercharge/request-ip": "^1.2.0",
21
21
  "@types/cors": "^2.8.17",
22
22
  "@types/express": "^4.17.21",
23
- "@types/node": "^20.12.2",
23
+ "@types/node": "^20.12.6",
24
24
  "@types/nodemailer": "^6.4.14",
25
25
  "@types/nodemailer-smtp-transport": "^2.7.8",
26
26
  "@types/serve-index": "^1.9.4",
@@ -28,10 +28,10 @@
28
28
  "@types/swagger-ui-express": "^4.1.6",
29
29
  "cors": "^2.8.5",
30
30
  "express": "^4.19.2",
31
- "joi": "^17.12.2",
32
- "namirasoft-core": "^1.3.15",
31
+ "joi": "^17.12.3",
32
+ "namirasoft-core": "^1.3.18",
33
33
  "namirasoft-log": "^1.3.6",
34
- "namirasoft-schema": "^1.3.4",
34
+ "namirasoft-schema": "^1.3.7",
35
35
  "nodemailer": "^6.9.13",
36
36
  "nodemailer-smtp-transport": "^2.7.4",
37
37
  "request-ip": "^3.3.0",
@@ -0,0 +1,39 @@
1
+ import nodemailer from 'nodemailer';
2
+ import Mail, { AttachmentLike } from "nodemailer/lib/mailer";
3
+ import { Readable } from "stream";
4
+
5
+ export abstract class BaseEmailService
6
+ {
7
+ username: string;
8
+ constructor(username: string)
9
+ {
10
+ this.username = username;
11
+ }
12
+ protected abstract getTransform(): any;
13
+ send(from: string | null, to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void)
14
+ {
15
+ let transform = this.getTransform();
16
+ let transporter = nodemailer.createTransport(transform);
17
+
18
+ let mailOptions: Mail.Options = {
19
+ from: from ?? this.username,
20
+ to,
21
+ subject,
22
+ text,
23
+ html
24
+ };
25
+ if (html)
26
+ mailOptions.html = html;
27
+
28
+ transporter.sendMail(mailOptions, function (error, info)
29
+ {
30
+ if (callback)
31
+ callback(error, info);
32
+ else
33
+ {
34
+ if (error)
35
+ console.log(error);
36
+ }
37
+ });
38
+ }
39
+ }
@@ -0,0 +1,23 @@
1
+ import smtpTransport from 'nodemailer-smtp-transport';
2
+ import { BaseEmailService } from './BaseEmailService';
3
+
4
+ export class Gmail extends BaseEmailService
5
+ {
6
+ password: string;
7
+ constructor(username: string, password: string)
8
+ {
9
+ super(username);
10
+ this.password = password;
11
+ }
12
+ protected override getTransform(): any
13
+ {
14
+ return smtpTransport({
15
+ service: 'gmail',
16
+ host: 'smtp.gmail.com',
17
+ auth: {
18
+ user: this.username,
19
+ pass: this.password
20
+ }
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseEmailService } from './BaseEmailService';
2
+
3
+ export class SMTPService extends BaseEmailService
4
+ {
5
+ host: string;
6
+ port: number;
7
+ password: string;
8
+ constructor(host: string, username: string, port: number, password: string)
9
+ {
10
+ super(username);
11
+ this.host = host;
12
+ this.port = port;
13
+ this.password = password;
14
+ }
15
+ protected override getTransform(): any
16
+ {
17
+ return {
18
+ host: this.host,
19
+ port: this.port,
20
+ secure: true,
21
+ auth: {
22
+ user: this.username,
23
+ pass: this.password
24
+ }
25
+ };
26
+ }
27
+ }
package/src/index.ts CHANGED
@@ -3,12 +3,14 @@ export * from "./BaseApplication";
3
3
  export * from "./BaseApplicationLink";
4
4
  export * from "./BaseController";
5
5
  export * from "./BaseDatabase";
6
+ export * from "./BaseEmailService";
6
7
  export * from "./BaseTable";
7
8
  export * from "./CommandOperation";
8
- export * from "./EmailService";
9
9
  export * from "./EnvService";
10
+ export * from "./GmailService";
10
11
  export * from "./IPOperation";
11
12
  export * from "./Meta";
12
13
  export * from "./OTPOperation";
13
14
  export * from "./RequestHeaderService";
14
- export * from "./ServerToServerOperation";
15
+ export * from "./ServerToServerOperation";
16
+ export * from "./SMTPService";
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { AttachmentLike } from "nodemailer/lib/mailer";
4
- import { Readable } from "stream";
5
- export declare class EmailService {
6
- host: string;
7
- username: string;
8
- username_from: string;
9
- password: string;
10
- error_title: string;
11
- error_recipients: string;
12
- constructor(host: string, username: string, username_from: string, password: string, error_title: string, error_recipients: string);
13
- sendExeption(error: Error, meta: any, callback?: (err: Error | null, info: any) => void): void;
14
- sendError(title: string, message: string, callback?: (err: Error | null, info: any) => void): void;
15
- send(to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void): void;
16
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EmailService = void 0;
7
- const nodemailer_1 = __importDefault(require("nodemailer"));
8
- const nodemailer_smtp_transport_1 = __importDefault(require("nodemailer-smtp-transport"));
9
- class EmailService {
10
- constructor(host, username, username_from, password, error_title, error_recipients) {
11
- this.host = host;
12
- this.username = username;
13
- this.username_from = username_from;
14
- this.password = password;
15
- this.error_title = error_title;
16
- this.error_recipients = error_recipients;
17
- }
18
- sendExeption(error, meta, callback) {
19
- let title = error.message;
20
- let message = title;
21
- if (meta)
22
- message += "\r\n" + JSON.stringify(meta);
23
- message += "\r\n" + error.stack;
24
- this.sendError(title, message, callback);
25
- }
26
- sendError(title, message, callback) {
27
- if (!title)
28
- title = '';
29
- let toks = this.error_recipients.split(',');
30
- for (let i = 0; i < toks.length; i++) {
31
- const email = toks[i];
32
- this.send(email, this.error_title + " - " + title, message, undefined, callback);
33
- }
34
- }
35
- send(to, subject, text, html, callback) {
36
- if (!this.username)
37
- return;
38
- if (!this.password)
39
- return;
40
- let transform = {};
41
- if (this.host === 'gmail')
42
- transform = (0, nodemailer_smtp_transport_1.default)({
43
- service: 'gmail',
44
- host: 'smtp.gmail.com',
45
- auth: {
46
- user: this.username,
47
- pass: this.password
48
- }
49
- });
50
- else
51
- transform = {
52
- host: this.host,
53
- port: 465,
54
- secure: true,
55
- auth: {
56
- user: this.username,
57
- pass: this.password
58
- }
59
- };
60
- let transporter = nodemailer_1.default.createTransport(transform);
61
- let mailOptions = {
62
- from: this.username_from,
63
- to,
64
- subject,
65
- text,
66
- html
67
- };
68
- if (html)
69
- mailOptions.html = html;
70
- transporter.sendMail(mailOptions, function (error, info) {
71
- if (callback)
72
- callback(error, info);
73
- else {
74
- if (error)
75
- console.log(error);
76
- }
77
- });
78
- }
79
- }
80
- exports.EmailService = EmailService;
81
- //# sourceMappingURL=EmailService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmailService.js","sourceRoot":"","sources":["../src/EmailService.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AACpC,0FAAsD;AAItD,MAAa,YAAY;IAQrB,YAAY,IAAY,EAAE,QAAgB,EAAE,aAAqB,EAAE,QAAgB,EAAE,WAAmB,EAAE,gBAAwB;QAE9H,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C,CAAC;IACD,YAAY,CAAC,KAAY,EAAE,IAAS,EAAE,QAAiD;QAEnF,IAAI,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;QAC1B,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,IAAI;YACJ,OAAO,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC7C,OAAO,IAAI,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC;QAChC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IACD,SAAS,CAAC,KAAa,EAAE,OAAe,EAAE,QAAiD;QAEvF,IAAI,CAAC,KAAK;YACN,KAAK,GAAG,EAAE,CAAC;QACf,IAAI,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EACpC;YACI,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACtB,IAAI,CAAC,IAAI,CACL,KAAK,EACL,IAAI,CAAC,WAAW,GAAG,KAAK,GAAG,KAAK,EAChC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAC/B,CAAC;SACL;IACL,CAAC;IACD,IAAI,CAAC,EAAU,EAAE,OAAe,EAAE,IAAY,EAAE,IAA8D,EAAE,QAAiD;QAE7J,IAAI,CAAC,IAAI,CAAC,QAAQ;YACd,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ;YACd,OAAO;QACX,IAAI,SAAS,GAAG,EAAE,CAAA;QAClB,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;YACrB,SAAS,GAAG,IAAA,mCAAa,EAAC;gBACtB,OAAO,EAAE,OAAO;gBAChB,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE;oBACF,IAAI,EAAE,IAAI,CAAC,QAAQ;oBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;iBACtB;aACJ,CAAC,CAAC;;YAEH,SAAS,GAAG;gBACR,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,GAAG;gBACT,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE;oBACF,IAAI,EAAE,IAAI,CAAC,QAAQ;oBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;iBACtB;aACJ,CAAC;QAEN,IAAI,WAAW,GAAG,oBAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAExD,IAAI,WAAW,GAAiB;YAC5B,IAAI,EAAE,IAAI,CAAC,aAAa;YACxB,EAAE;YACF,OAAO;YACP,IAAI;YACJ,IAAI;SACP,CAAC;QACF,IAAI,IAAI;YACJ,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;QAE5B,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,UAAU,KAAK,EAAE,IAAI;YAEnD,IAAI,QAAQ;gBACR,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAE1B;gBACI,IAAI,KAAK;oBACL,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aAC1B;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA3FD,oCA2FC"}
@@ -1,97 +0,0 @@
1
- import nodemailer from 'nodemailer';
2
- import smtpTransport from 'nodemailer-smtp-transport';
3
- import Mail, { AttachmentLike } from "nodemailer/lib/mailer";
4
- import { Readable } from "stream";
5
-
6
- export class EmailService
7
- {
8
- host: string;
9
- username: string;
10
- username_from: string;
11
- password: string;
12
- error_title: string;
13
- error_recipients: string;
14
- constructor(host: string, username: string, username_from: string, password: string, error_title: string, error_recipients: string)
15
- {
16
- this.host = host;
17
- this.username = username;
18
- this.username_from = username_from;
19
- this.password = password;
20
- this.error_title = error_title;
21
- this.error_recipients = error_recipients;
22
- }
23
- sendExeption(error: Error, meta: any, callback?: (err: Error | null, info: any) => void)
24
- {
25
- let title = error.message;
26
- let message = title;
27
- if (meta)
28
- message += "\r\n" + JSON.stringify(meta);
29
- message += "\r\n" + error.stack;
30
- this.sendError(title, message, callback);
31
- }
32
- sendError(title: string, message: string, callback?: (err: Error | null, info: any) => void)
33
- {
34
- if (!title)
35
- title = '';
36
- let toks = this.error_recipients.split(',');
37
- for (let i = 0; i < toks.length; i++)
38
- {
39
- const email = toks[i];
40
- this.send(
41
- email,
42
- this.error_title + " - " + title,
43
- message, undefined, callback
44
- );
45
- }
46
- }
47
- send(to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void)
48
- {
49
- if (!this.username)
50
- return;
51
- if (!this.password)
52
- return;
53
- let transform = {}
54
- if (this.host === 'gmail')
55
- transform = smtpTransport({
56
- service: 'gmail',
57
- host: 'smtp.gmail.com',
58
- auth: {
59
- user: this.username,
60
- pass: this.password
61
- }
62
- });
63
- else
64
- transform = {
65
- host: this.host,
66
- port: 465,
67
- secure: true,
68
- auth: {
69
- user: this.username,
70
- pass: this.password
71
- }
72
- };
73
-
74
- let transporter = nodemailer.createTransport(transform);
75
-
76
- let mailOptions: Mail.Options = {
77
- from: this.username_from,
78
- to,
79
- subject,
80
- text,
81
- html
82
- };
83
- if (html)
84
- mailOptions.html = html;
85
-
86
- transporter.sendMail(mailOptions, function (error, info)
87
- {
88
- if (callback)
89
- callback(error, info);
90
- else
91
- {
92
- if (error)
93
- console.log(error);
94
- }
95
- });
96
- }
97
- }