2025-03-25 08:54:22 +00:00
|
|
|
import { exec } from 'child_process';
|
|
|
|
|
2025-03-25 11:39:58 +00:00
|
|
|
const nodemailer = require('nodemailer');
|
|
|
|
|
2025-03-25 08:54:22 +00:00
|
|
|
exec('iching divine', (error, stdout, stderr) => {
|
|
|
|
|
2025-03-25 14:04:48 +00:00
|
|
|
console.log(`Begin`);
|
2025-03-25 08:54:22 +00:00
|
|
|
|
|
|
|
if (error) {
|
2025-03-25 14:04:48 +00:00
|
|
|
console.error(`Error: ${error.message}`);
|
2025-03-25 08:54:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stderr) {
|
|
|
|
console.error(`Stderr: ${stderr}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-03-25 11:39:58 +00:00
|
|
|
//console.log(`Ergebnis:\n${stdout}`);
|
2025-03-25 08:54:22 +00:00
|
|
|
|
2025-03-25 14:04:48 +00:00
|
|
|
console.log(`Send E-Mail`);
|
|
|
|
|
2025-03-26 11:44:42 +00:00
|
|
|
sendEmail(stdout);
|
|
|
|
|
|
|
|
sleep();
|
2025-03-25 08:54:22 +00:00
|
|
|
});
|
2025-03-25 11:39:58 +00:00
|
|
|
|
2025-03-26 11:44:42 +00:00
|
|
|
// Create Transporter
|
2025-03-25 11:39:58 +00:00
|
|
|
const transporter = nodemailer.createTransport({
|
|
|
|
host: "mailhog.mailhog.svc.cluster.local", // MailHog ClusterIP
|
|
|
|
port: 1025, // Standard-MailHog SMTP-Port
|
2025-03-26 11:44:42 +00:00
|
|
|
secure: false // MailHog needs no encryption
|
|
|
|
});
|
2025-03-25 11:39:58 +00:00
|
|
|
|
2025-03-26 11:44:42 +00:00
|
|
|
// Send E-Mail
|
|
|
|
async function sendEmail(content: string) {
|
|
|
|
try {
|
|
|
|
const info = await transporter.sendMail({
|
2025-03-26 14:55:41 +00:00
|
|
|
from: '"The Oracle" <the.oracle@holy.mountain>',
|
2025-03-26 11:44:42 +00:00
|
|
|
to: "Christopher.Hase@telekom.com;test@mailhog.local",
|
2025-03-27 08:52:03 +00:00
|
|
|
subject: "Your Horoscope Is Ready",
|
2025-03-26 11:44:42 +00:00
|
|
|
text: content,
|
2025-03-26 14:21:12 +00:00
|
|
|
//html: "<p> ${content} </p>"
|
2025-03-27 08:52:03 +00:00
|
|
|
html: html(content)
|
|
|
|
//html: content
|
2025-03-26 11:44:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
console.log("E-Mail sent: ", info.messageId);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error Sending E-Mail:", error);
|
2025-03-25 11:39:58 +00:00
|
|
|
}
|
2025-03-26 11:44:42 +00:00
|
|
|
}
|
|
|
|
|
2025-03-26 14:21:12 +00:00
|
|
|
//Sleep. To avoid issue in pod: Completed -> Terminated -> CrashLoopBackOff
|
2025-03-26 11:44:42 +00:00
|
|
|
async function sleep() {
|
|
|
|
console.log("Go to sleep: ", new Date().toISOString());
|
|
|
|
|
|
|
|
// sleep 1h (3600000 ms)
|
|
|
|
setTimeout(() => {
|
|
|
|
sleep(); // recursion after 1h
|
|
|
|
}, 3600000);
|
|
|
|
}
|
2025-03-26 14:21:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function html(input: string): string {
|
|
|
|
|
|
|
|
// Zerlege den String in einzelne Zeilen
|
|
|
|
const lines = input.split("\n");
|
|
|
|
|
|
|
|
// Bearbeite jede Zeile (z.B. trimme Leerzeichen und füge einen Prefix hinzu)
|
2025-03-26 14:34:52 +00:00
|
|
|
//const processedLines = lines.map(line => `> ${line.trim()}`);
|
|
|
|
const processedLines = lines.map(line => processLine(line));
|
2025-03-26 14:21:12 +00:00
|
|
|
|
|
|
|
// Füge die Zeilen wieder zu einem String zusammen
|
|
|
|
return processedLines.join("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: process every line...
|
|
|
|
function processLine(input: string): string {
|
|
|
|
|
2025-03-27 08:52:03 +00:00
|
|
|
//return input + "\n";
|
|
|
|
//"<p> ${content} </p>"
|
|
|
|
return "<p>" + input + "</p>";
|
2025-03-26 14:21:12 +00:00
|
|
|
}
|
2025-03-25 11:39:58 +00:00
|
|
|
|