First Commit
This commit is contained in:
commit
66fdedcb1e
6
.editorconfig
Normal file
6
.editorconfig
Normal file
@ -0,0 +1,6 @@
|
||||
root=true
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_size = 3
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
lib/
|
||||
config.ini
|
2132
package-lock.json
generated
Normal file
2132
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
package.json
Normal file
35
package.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@hibas123/issc",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "lib/index.js",
|
||||
"bin": "lib/index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon -e ts --exec ts-node src/index.ts",
|
||||
"build": "tsc && pkg ."
|
||||
},
|
||||
"pkg": {
|
||||
"targets": [
|
||||
"node12-linux"
|
||||
]
|
||||
},
|
||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/ini": "^1.3.30",
|
||||
"@types/node": "^14.0.23",
|
||||
"@types/nodemailer": "^6.4.0",
|
||||
"@types/yargs": "^15.0.5",
|
||||
"nodemon": "^2.0.4",
|
||||
"pkg": "^4.4.9",
|
||||
"ts-node": "^8.10.2",
|
||||
"typescript": "^3.9.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hibas123/nodelogging": "^2.4.5",
|
||||
"get-stdin": "^8.0.0",
|
||||
"ini": "^1.3.5",
|
||||
"nodemailer": "^6.4.10",
|
||||
"yargs": "^15.4.1"
|
||||
}
|
||||
}
|
113
src/index.ts
Normal file
113
src/index.ts
Normal file
@ -0,0 +1,113 @@
|
||||
process.env.LOGGING_NO_DEFAULT = "true";
|
||||
import { LoggingBase, ConsoleAdapter } from "@hibas123/logging";
|
||||
|
||||
import * as yargs from "yargs";
|
||||
|
||||
const options = yargs
|
||||
.option("verbose", {
|
||||
alias: "v",
|
||||
type: "boolean",
|
||||
description: "Print debug informations",
|
||||
required: false,
|
||||
})
|
||||
.option("config", {
|
||||
alias: "c",
|
||||
type: "string",
|
||||
default: "/etc/issc.ini",
|
||||
description: "Config file location",
|
||||
})
|
||||
.option("to", {
|
||||
alias: "t",
|
||||
description: "The receiver of the email",
|
||||
type: "string",
|
||||
required: true,
|
||||
})
|
||||
.option("subject", {
|
||||
alias: "s",
|
||||
description: "Subject of the mail",
|
||||
type: "string",
|
||||
required: false,
|
||||
}).argv;
|
||||
|
||||
const Logging = new LoggingBase({
|
||||
console: false,
|
||||
});
|
||||
|
||||
if (options.verbose) {
|
||||
Logging.addAdapter(new ConsoleAdapter(true));
|
||||
}
|
||||
|
||||
Logging.log("Starting INSANLY SIMPLE SMTP CLIENT");
|
||||
|
||||
const EXAMPLE_CONFIG = `
|
||||
[smtp]
|
||||
server=
|
||||
from=
|
||||
username=
|
||||
password=
|
||||
port=
|
||||
`;
|
||||
|
||||
import * as nm from "nodemailer";
|
||||
|
||||
import * as ini from "ini";
|
||||
import { readFileSync, fstat, existsSync } from "fs";
|
||||
|
||||
Logging.log("Loading configuration");
|
||||
|
||||
if (!existsSync(options.config)) {
|
||||
console.log(
|
||||
"Add configuration to /etc/issc.ini or set your location by using --config <path>. \n\n Example config: \n\n" +
|
||||
EXAMPLE_CONFIG
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const config = ini.parse(readFileSync(options.config, "utf-8"));
|
||||
Logging.log("Creating Transport");
|
||||
const transport = nm.createTransport({
|
||||
host: config.smtp.server,
|
||||
port: Number(config.smtp.port || 587),
|
||||
secure: false,
|
||||
auth: {
|
||||
user: config.smtp.username,
|
||||
pass: config.smtp.password,
|
||||
method: "PLAIN",
|
||||
},
|
||||
logger: {
|
||||
fatal: Logging.errorMessage,
|
||||
trace: Logging.log,
|
||||
level: () => undefined,
|
||||
debug: Logging.debug,
|
||||
error: Logging.errorMessage,
|
||||
info: Logging.log,
|
||||
warn: Logging.warn,
|
||||
},
|
||||
});
|
||||
Logging.log("Verifying transport");
|
||||
|
||||
import getstdin = require("get-stdin");
|
||||
|
||||
transport
|
||||
.verify()
|
||||
.then(async () => {
|
||||
Logging.log("Reading STDIN");
|
||||
const text = await getstdin();
|
||||
Logging.log("Sending mail");
|
||||
const res = await transport.sendMail({
|
||||
from: config.smtp.from,
|
||||
to: options.to,
|
||||
subject: options.subject,
|
||||
text,
|
||||
});
|
||||
|
||||
console.log("Message sent");
|
||||
})
|
||||
.catch((err) => {
|
||||
Logging.error(err);
|
||||
console.log("Some error occured!", err.message);
|
||||
})
|
||||
.finally(() => {
|
||||
transport.close();
|
||||
process.exit();
|
||||
});
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "lib/",
|
||||
"target": "ESNext",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user