@vroskus/library-email 1.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/dist/index.js +82 -0
- package/package.json +42 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
var _EmailService_instances, _EmailService_setupTransporter;
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
22
|
+
const html_to_text_1 = require("html-to-text");
|
|
23
|
+
class EmailService {
|
|
24
|
+
constructor({ email, from, host, password, port, username, }) {
|
|
25
|
+
_EmailService_instances.add(this);
|
|
26
|
+
this.from = `"${from}" <${email}>`;
|
|
27
|
+
__classPrivateFieldGet(this, _EmailService_instances, "m", _EmailService_setupTransporter).call(this, {
|
|
28
|
+
host,
|
|
29
|
+
password,
|
|
30
|
+
port: port || '25',
|
|
31
|
+
username,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
sendMail({ bcc, content, replyTo, subject, to, }) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const params = {
|
|
37
|
+
bcc,
|
|
38
|
+
from: this.from,
|
|
39
|
+
html: content,
|
|
40
|
+
replyTo,
|
|
41
|
+
subject,
|
|
42
|
+
text: (0, html_to_text_1.htmlToText)(content),
|
|
43
|
+
to,
|
|
44
|
+
};
|
|
45
|
+
const info = yield this.transporter.sendMail(params);
|
|
46
|
+
console.log('info', info);
|
|
47
|
+
return info.messageId;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
_EmailService_instances = new WeakSet(), _EmailService_setupTransporter = function _EmailService_setupTransporter({ host, password, port, username, }) {
|
|
52
|
+
this.transporter = {
|
|
53
|
+
sendMail: ({ bcc, html, subject, text, to, }) => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
console.log('\x1b[33m', 'EmailService.sendEmail', '\x1b[0m\x1b[90m', to, bcc, subject, JSON.stringify(html), JSON.stringify(text));
|
|
55
|
+
return {
|
|
56
|
+
accepted: Array.isArray(to) ? to : [to],
|
|
57
|
+
messageId: '0',
|
|
58
|
+
pending: [],
|
|
59
|
+
rejected: [],
|
|
60
|
+
response: 'Email sent by dummy service',
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
if (host !== '') {
|
|
65
|
+
let auth;
|
|
66
|
+
if (username && password) {
|
|
67
|
+
auth = {
|
|
68
|
+
pass: password,
|
|
69
|
+
user: username,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const params = {
|
|
73
|
+
auth,
|
|
74
|
+
host,
|
|
75
|
+
port,
|
|
76
|
+
secure: false,
|
|
77
|
+
};
|
|
78
|
+
this.transporter = nodemailer_1.default.createTransport(params);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.default = EmailService;
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vroskus/library-email",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Email",
|
|
5
|
+
"author": "Vilius Roškus <vilius@regattas.eu>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/vroskus/library-email.git"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/index.js"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "npm run build",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"test": "npm run test:eslint && npm run test:e2e",
|
|
19
|
+
"test:eslint": "eslint src --fix",
|
|
20
|
+
"test:e2e": "echo 'No tests'"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"html-to-text": "9.0.4",
|
|
24
|
+
"lodash": "4.17.21",
|
|
25
|
+
"nodemailer": "6.9.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/jest": "29.5.0",
|
|
29
|
+
"@types/node": "18.15.11",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "5.53.0",
|
|
31
|
+
"@typescript-eslint/parser": "5.53.0",
|
|
32
|
+
"eslint": "8.34.0",
|
|
33
|
+
"eslint-config-airbnb-base": "15.0.0",
|
|
34
|
+
"eslint-config-airbnb-typescript": "17.0.0",
|
|
35
|
+
"eslint-plugin-import": "2.27.5",
|
|
36
|
+
"eslint-plugin-import-newlines": "1.3.1",
|
|
37
|
+
"eslint-plugin-react": "7.32.2",
|
|
38
|
+
"eslint-plugin-sort": "2.4.0",
|
|
39
|
+
"npm-check": "6.0.1",
|
|
40
|
+
"typescript": "4.9.5"
|
|
41
|
+
}
|
|
42
|
+
}
|