diff --git a/Dockerfile b/Dockerfile index 6fa2e7a..55dd1a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # 1. Nutze Node.js als Basisimage #TODO: node:20 !!! -FROM node:18-alpine +#FROM node:18-alpine +FROM node:20.18.1 # 2. Setze das Arbeitsverzeichnis WORKDIR /app @@ -9,13 +10,26 @@ COPY package*.json ./ # 4. Installiere Abhängigkeiten RUN npm install -RUN npm i --save-dev @types/nodemailer +#RUN npm i --save-dev @types/nodemailer +#RUN npm i -g npx + +RUN npx tsc + +#RUN apt install cargo +RUN apt update && apt install -y cargo && rm -rf /var/lib/apt/lists/* + +#RUN cargo install iching +FROM rust:1.74.0 +RUN cargo install iching # 5. Kopiere den Rest des Codes COPY . . # 6. Kompiliere TypeScript (optional, falls ts-node nicht genutzt wird) -RUN npx tsc +#FROM node:20.18.1 +#RUN npx tsc +#RUN ["npx","tsc"] # 7. Starte das TypeScript-Skript mit ts-node -CMD ["npx", "ts-node", "mailsender.ts"] \ No newline at end of file +#CMD ["npx", "ts-node", "mailsender.ts"] +CMD ["npx", "ts-node", "broker.ts"] \ No newline at end of file diff --git a/broker.ts b/broker.ts index d82604a..547ec2a 100644 --- a/broker.ts +++ b/broker.ts @@ -1,7 +1,7 @@ - - import { exec } from 'child_process'; +const nodemailer = require('nodemailer'); + exec('iching divine', (error, stdout, stderr) => { console.log(`Beginn`); @@ -17,6 +17,33 @@ exec('iching divine', (error, stdout, stderr) => { return; } - console.log(`Ergebnis:\n${stdout}`); + //console.log(`Ergebnis:\n${stdout}`); + sendEmail(stdout); //TODO: param }); + +// Erstelle den Transporter +const transporter = nodemailer.createTransport({ + //host: "localhost", // MailHog läuft standardmäßig auf localhost + host: "mailhog.mailhog.svc.cluster.local", // MailHog ClusterIP + port: 1025, // Standard-MailHog SMTP-Port + secure: false // MailHog benötigt keine Verschlüsselung + }); + + // E-Mail senden + async function sendEmail(content: string) { //TODO: param + try { + const info = await transporter.sendMail({ + from: '"Test Sender" ', + to: "Christopher.Hase@telekom.com;test@mailhog.local", + subject: "Hallo von MailHog", + text: content, + html: "

${content}

" + }); + + console.log("E-Mail gesendet: ", info.messageId); + } catch (error) { + console.error("Fehler beim Senden der E-Mail:", error); + } + } + \ No newline at end of file