@mysetup/nodemailer 1.5.2 → 1.5.4

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,3 +1,9 @@
1
1
  import { type SendEmailEnv, type SendEmailInput } from "./types";
2
- export declare const connectNodeMailer: (data: SendEmailInput, config: SendEmailEnv) => Promise<string | undefined>;
2
+ /**
3
+ * Connects to the NodeMailer service and sends an email.
4
+ * @param data - The email data to send.
5
+ * @param config - The email configuration.
6
+ * @returns A promise that resolves to the result of the email sending operation.
7
+ */
8
+ export declare const connectNodeMailer: (data: SendEmailInput, config: SendEmailEnv) => Promise<string>;
3
9
  //# sourceMappingURL=nodemailer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodemailer.d.ts","sourceRoot":"","sources":["../nodemailer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAyCjE,eAAO,MAAM,iBAAiB,GAC1B,MAAM,cAAc,EACpB,QAAQ,YAAY,gCA4CvB,CAAC"}
1
+ {"version":3,"file":"nodemailer.d.ts","sourceRoot":"","sources":["../nodemailer.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAgCjE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC1B,MAAM,cAAc,EACpB,QAAQ,YAAY,oBAqCvB,CAAC"}
@@ -40,59 +40,72 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.connectNodeMailer = void 0;
43
- /* eslint-disable @typescript-eslint/no-unsafe-call */
44
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
45
43
  var node_path_1 = __importDefault(require("node:path"));
46
44
  var ejs_1 = __importDefault(require("ejs"));
47
45
  var logger_1 = require("@mysetup/logger");
48
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
49
- var nodemailer = require("nodemailer");
50
- var sendMail = function (mailOptions, env) {
51
- return new Promise(function (resolve, reject) {
52
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
53
- var transporter = nodemailer.createTransport({
54
- service: "gmail",
55
- auth: {
56
- user: env.user,
57
- pass: env.pass,
58
- },
59
- tls: {
60
- // :point_down: this skips cert verification
61
- rejectUnauthorized: false,
62
- },
63
- }, {
64
- from: env.from,
65
- });
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- transporter.sendMail(mailOptions, function (error, info) {
68
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
69
- if (error) {
70
- logger_1.logger.error(error);
71
- reject(error);
72
- }
73
- else {
74
- resolve("Email sent: ".concat(info.response));
46
+ var nodemailer_1 = __importDefault(require("nodemailer"));
47
+ var sendMail = function (mailOptions, env) { return __awaiter(void 0, void 0, void 0, function () {
48
+ var transporter, info, error_1;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ transporter = nodemailer_1.default.createTransport({
53
+ service: "gmail",
54
+ auth: {
55
+ user: env.user,
56
+ pass: env.pass,
57
+ },
58
+ tls: {
59
+ rejectUnauthorized: false,
60
+ },
61
+ }, {
62
+ from: env.from,
63
+ });
64
+ _a.label = 1;
65
+ case 1:
66
+ _a.trys.push([1, 3, , 4]);
67
+ return [4 /*yield*/, transporter.sendMail(mailOptions)];
68
+ case 2:
69
+ info = _a.sent();
75
70
  logger_1.logger.info("Email sent: ".concat(info.response));
76
- }
77
- });
71
+ return [2 /*return*/, "Email sent: ".concat(info.response)];
72
+ case 3:
73
+ error_1 = _a.sent();
74
+ logger_1.logger.error("Error sending email: ".concat(error_1));
75
+ throw error_1;
76
+ case 4: return [2 /*return*/];
77
+ }
78
78
  });
79
- };
79
+ }); };
80
+ /**
81
+ * Connects to the NodeMailer service and sends an email.
82
+ * @param data - The email data to send.
83
+ * @param config - The email configuration.
84
+ * @returns A promise that resolves to the result of the email sending operation.
85
+ */
80
86
  var connectNodeMailer = function (data, config) { return __awaiter(void 0, void 0, void 0, function () {
81
- var templatePath, htmlTemplate, mailOptions, env, error_1;
82
- var _a;
83
- return __generator(this, function (_b) {
84
- switch (_b.label) {
87
+ var templatePath, htmlTemplate, _a, mailOptions, error_2;
88
+ var _b;
89
+ return __generator(this, function (_c) {
90
+ switch (_c.label) {
85
91
  case 0:
86
- _b.trys.push([0, 3, , 4]);
92
+ _c.trys.push([0, 5, , 6]);
87
93
  templatePath = node_path_1.default.join(__dirname, "views", "".concat(data.template, ".ejs"));
88
- return [4 /*yield*/, ejs_1.default.renderFile(templatePath, data.value)];
89
- case 1:
90
- htmlTemplate = _b.sent();
94
+ if (!data.htmlTemplate) return [3 /*break*/, 1];
95
+ _a = data.htmlTemplate;
96
+ return [3 /*break*/, 3];
97
+ case 1: return [4 /*yield*/, ejs_1.default.renderFile(templatePath, data.value)];
98
+ case 2:
99
+ _a = _c.sent();
100
+ _c.label = 3;
101
+ case 3:
102
+ htmlTemplate = _a;
91
103
  mailOptions = {
92
- to: data.toEmail,
104
+ to: config.from,
105
+ bcc: data.toEmail,
93
106
  subject: data.subject,
94
107
  html: htmlTemplate,
95
- attachments: (_a = data.attachments) === null || _a === void 0 ? void 0 : _a.map(function (attachment) { return ({
108
+ attachments: (_b = data.attachments) === null || _b === void 0 ? void 0 : _b.map(function (attachment) { return ({
96
109
  filename: attachment.filename,
97
110
  content: attachment.content,
98
111
  path: attachment.path,
@@ -102,20 +115,13 @@ var connectNodeMailer = function (data, config) { return __awaiter(void 0, void
102
115
  raw: attachment.raw,
103
116
  }); }),
104
117
  };
105
- env = {
106
- user: config.user,
107
- pass: config.pass,
108
- from: config.from,
109
- };
110
- return [4 /*yield*/, sendMail(mailOptions, env)];
111
- case 2:
112
- // Send email
113
- return [2 /*return*/, _b.sent()];
114
- case 3:
115
- error_1 = _b.sent();
116
- logger_1.logger.error(error_1);
117
- return [3 /*break*/, 4];
118
- case 4: return [2 /*return*/];
118
+ return [4 /*yield*/, sendMail(mailOptions, config)];
119
+ case 4: return [2 /*return*/, _c.sent()];
120
+ case 5:
121
+ error_2 = _c.sent();
122
+ logger_1.logger.error(error_2);
123
+ throw error_2; // rethrow so caller can handle
124
+ case 6: return [2 /*return*/];
119
125
  }
120
126
  });
121
127
  }); };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test-nodemailer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-nodemailer.d.ts","sourceRoot":"","sources":["../../test/test-nodemailer.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var _a, _b, _c;
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ var logger_1 = require("@mysetup/logger");
41
+ var nodemailer_1 = require("../nodemailer");
42
+ var config = {
43
+ user: (_a = process.env.SMTP_EMAIL) !== null && _a !== void 0 ? _a : "",
44
+ pass: (_b = process.env.SMTP_PASS) !== null && _b !== void 0 ? _b : "",
45
+ from: (_c = process.env.SMTP_FROM) !== null && _c !== void 0 ? _c : "",
46
+ };
47
+ var data = {
48
+ template: "test",
49
+ value: { fromName: "krishnaraj" },
50
+ toEmail: "krishna42cse@gmail.com",
51
+ subject: "Test Email from Nodemailer + Nodemon",
52
+ };
53
+ function init() {
54
+ return __awaiter(this, void 0, void 0, function () {
55
+ var result, err_1;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0:
59
+ _a.trys.push([0, 2, , 3]);
60
+ return [4 /*yield*/, (0, nodemailer_1.connectNodeMailer)(data, config)];
61
+ case 1:
62
+ result = _a.sent();
63
+ logger_1.logger.info(result);
64
+ return [3 /*break*/, 3];
65
+ case 2:
66
+ err_1 = _a.sent();
67
+ logger_1.logger.error("Failed to send email:", err_1);
68
+ return [3 /*break*/, 3];
69
+ case 3: return [2 /*return*/];
70
+ }
71
+ });
72
+ });
73
+ }
74
+ void init();
@@ -7,8 +7,9 @@ export interface SendEmailEnv {
7
7
  export interface SendEmailInput {
8
8
  subject: string;
9
9
  toEmail: string;
10
+ htmlTemplate?: string;
10
11
  template: string;
11
- value: JSON;
12
+ value: object;
12
13
  attachments?: {
13
14
  filename?: string;
14
15
  content?: string | Buffer | Readable;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,CAAC,EAAE;QACV,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;QACrC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;KACpC,EAAE,CAAC;CACP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE;QACV,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;QACrC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;KACpC,EAAE,CAAC;CACP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysetup/nodemailer",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -15,6 +15,7 @@
15
15
  "./package.json": "./package.json"
16
16
  },
17
17
  "scripts": {
18
+ "dev": "nodemon",
18
19
  "lint": "eslint .",
19
20
  "typecheck": "tsc --noEmit",
20
21
  "build": "rm -rf ./dist && tsc",
@@ -35,6 +36,8 @@
35
36
  "@types/node": "^22.13.1",
36
37
  "@types/nodemailer": "^6.4.17",
37
38
  "eslint": "8.57.0",
39
+ "nodemon": "3.1.7",
40
+ "ts-node": "^10.9.2",
38
41
  "typescript": "^5.7.3"
39
42
  },
40
43
  "prettier": "@mysetup/prettier-config",