mikromail 0.0.1
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/README.md +99 -0
- package/lib/Configuration.d.mts +41 -0
- package/lib/Configuration.d.ts +41 -0
- package/lib/Configuration.js +153 -0
- package/lib/Configuration.mjs +7 -0
- package/lib/MikroMail.d.mts +30 -0
- package/lib/MikroMail.d.ts +30 -0
- package/lib/MikroMail.js +806 -0
- package/lib/MikroMail.mjs +10 -0
- package/lib/SMTPClient.d.mts +106 -0
- package/lib/SMTPClient.d.ts +106 -0
- package/lib/SMTPClient.js +632 -0
- package/lib/SMTPClient.mjs +7 -0
- package/lib/chunk-47VXJTWV.mjs +13 -0
- package/lib/chunk-TCYL3UFZ.mjs +541 -0
- package/lib/chunk-UDLJWUFN.mjs +83 -0
- package/lib/chunk-V2NYOKWA.mjs +121 -0
- package/lib/chunk-XNGASLEZ.mjs +42 -0
- package/lib/errors/index.d.mts +8 -0
- package/lib/errors/index.d.ts +8 -0
- package/lib/errors/index.js +37 -0
- package/lib/errors/index.mjs +6 -0
- package/lib/index.d.mts +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +806 -0
- package/lib/index.mjs +10 -0
- package/lib/interfaces/index.d.mts +60 -0
- package/lib/interfaces/index.d.ts +60 -0
- package/lib/interfaces/index.js +18 -0
- package/lib/interfaces/index.mjs +0 -0
- package/lib/utils/index.d.mts +19 -0
- package/lib/utils/index.d.ts +19 -0
- package/lib/utils/index.js +110 -0
- package/lib/utils/index.mjs +12 -0
- package/package.json +56 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidationError
|
|
3
|
+
} from "./chunk-47VXJTWV.mjs";
|
|
4
|
+
|
|
5
|
+
// src/Configuration.ts
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
var Configuration = class {
|
|
8
|
+
config;
|
|
9
|
+
defaults = {
|
|
10
|
+
configFilePath: "mikromail.config.json",
|
|
11
|
+
args: []
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @description Creates a new Configuration instance
|
|
15
|
+
* @param configFilePath Path to the configuration file (e.g., 'mikromail.config.json')
|
|
16
|
+
* @param args Command line arguments array from process.argv
|
|
17
|
+
*/
|
|
18
|
+
constructor(options) {
|
|
19
|
+
const configuration = options?.config || {};
|
|
20
|
+
const configFilePath = options?.configFilePath || this.defaults.configFilePath;
|
|
21
|
+
const args = options?.args || this.defaults.args;
|
|
22
|
+
this.config = this.create(configFilePath, args, configuration);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @description Creates a configuration object by merging defaults, config file settings,
|
|
26
|
+
* and CLI arguments (in order of increasing precedence)
|
|
27
|
+
* @param configFilePath Path to the configuration file
|
|
28
|
+
* @param args Command line arguments array
|
|
29
|
+
* @returns The merged configuration object
|
|
30
|
+
*/
|
|
31
|
+
create(configFilePath, args, configuration) {
|
|
32
|
+
const defaults = {
|
|
33
|
+
host: "",
|
|
34
|
+
user: "",
|
|
35
|
+
password: "",
|
|
36
|
+
port: 465,
|
|
37
|
+
secure: true,
|
|
38
|
+
debug: false,
|
|
39
|
+
maxRetries: 2
|
|
40
|
+
};
|
|
41
|
+
let fileConfig = {};
|
|
42
|
+
if (existsSync(configFilePath)) {
|
|
43
|
+
try {
|
|
44
|
+
const fileContent = readFileSync(configFilePath, "utf8");
|
|
45
|
+
fileConfig = JSON.parse(fileContent);
|
|
46
|
+
console.log(`Loaded configuration from ${configFilePath}`);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(
|
|
49
|
+
`Error reading config file: ${error instanceof Error ? error.message : String(error)}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const cliConfig = this.parseCliArgs(args);
|
|
54
|
+
return {
|
|
55
|
+
...defaults,
|
|
56
|
+
...configuration,
|
|
57
|
+
...fileConfig,
|
|
58
|
+
...cliConfig
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description Parses command line arguments into a configuration object
|
|
63
|
+
* @param args Command line arguments array
|
|
64
|
+
* @returns Parsed CLI configuration
|
|
65
|
+
*/
|
|
66
|
+
parseCliArgs(args) {
|
|
67
|
+
const cliConfig = {};
|
|
68
|
+
for (let i = 2; i < args.length; i++) {
|
|
69
|
+
const arg = args[i];
|
|
70
|
+
switch (arg) {
|
|
71
|
+
case "--host":
|
|
72
|
+
if (i + 1 < args.length) cliConfig.host = args[++i];
|
|
73
|
+
break;
|
|
74
|
+
case "--user":
|
|
75
|
+
if (i + 1 < args.length) cliConfig.user = args[++i];
|
|
76
|
+
break;
|
|
77
|
+
case "--password":
|
|
78
|
+
if (i + 1 < args.length) cliConfig.password = args[++i];
|
|
79
|
+
break;
|
|
80
|
+
case "--port":
|
|
81
|
+
if (i + 1 < args.length) {
|
|
82
|
+
const value = Number.parseInt(args[++i], 10);
|
|
83
|
+
if (!Number.isNaN(value)) cliConfig.port = value;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case "--secure":
|
|
87
|
+
cliConfig.secure = true;
|
|
88
|
+
break;
|
|
89
|
+
case "--debug":
|
|
90
|
+
cliConfig.debug = true;
|
|
91
|
+
break;
|
|
92
|
+
case "--retries":
|
|
93
|
+
if (i + 1 < args.length) {
|
|
94
|
+
const value = Number.parseInt(args[++i], 10);
|
|
95
|
+
if (!Number.isNaN(value)) cliConfig.maxRetries = value;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return cliConfig;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @description Validates the configuration
|
|
104
|
+
* @throws Error if the configuration is invalid
|
|
105
|
+
*/
|
|
106
|
+
validate() {
|
|
107
|
+
if (!this.config.host) throw new ValidationError("Host value not found");
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @description Returns the complete configuration
|
|
111
|
+
* @returns The configuration object
|
|
112
|
+
*/
|
|
113
|
+
get() {
|
|
114
|
+
this.validate();
|
|
115
|
+
return this.config;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
Configuration
|
|
121
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Configuration
|
|
3
|
+
} from "./chunk-V2NYOKWA.mjs";
|
|
4
|
+
import {
|
|
5
|
+
SMTPClient
|
|
6
|
+
} from "./chunk-TCYL3UFZ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
verifyEmailDomain
|
|
9
|
+
} from "./chunk-UDLJWUFN.mjs";
|
|
10
|
+
|
|
11
|
+
// src/MikroMail.ts
|
|
12
|
+
var MikroMail = class {
|
|
13
|
+
smtpClient;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const config = new Configuration(options).get();
|
|
16
|
+
const smtpClient = new SMTPClient(config);
|
|
17
|
+
this.smtpClient = smtpClient;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sends an email to valid domains.
|
|
21
|
+
*/
|
|
22
|
+
async send(emailOptions) {
|
|
23
|
+
try {
|
|
24
|
+
const hasMXRecords = await verifyEmailDomain(emailOptions.to);
|
|
25
|
+
if (!hasMXRecords)
|
|
26
|
+
console.error("Warning: No MX records found for recipient domain");
|
|
27
|
+
const result = await this.smtpClient.sendEmail(emailOptions);
|
|
28
|
+
if (result.success) console.log(`Message ID: ${result.messageId}`);
|
|
29
|
+
else console.error(`Failed to send email: ${result.error}`);
|
|
30
|
+
await this.smtpClient.close();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(
|
|
33
|
+
"Error in email sending process:",
|
|
34
|
+
error.message
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
MikroMail
|
|
42
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/errors/index.ts
|
|
21
|
+
var errors_exports = {};
|
|
22
|
+
__export(errors_exports, {
|
|
23
|
+
ValidationError: () => ValidationError
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(errors_exports);
|
|
26
|
+
var ValidationError = class extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super();
|
|
29
|
+
this.name = "ValidationError";
|
|
30
|
+
this.message = message;
|
|
31
|
+
this.cause = { statusCode: 400 };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
ValidationError
|
|
37
|
+
});
|
package/lib/index.d.mts
ADDED
package/lib/index.d.ts
ADDED