broker.ts
This commit is contained in:
parent
a1a3f831be
commit
7ea79ef4e7
2 changed files with 48 additions and 7 deletions
22
Dockerfile
22
Dockerfile
|
@ -1,5 +1,6 @@
|
||||||
# 1. Nutze Node.js als Basisimage #TODO: node:20 !!!
|
# 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
|
# 2. Setze das Arbeitsverzeichnis
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@ -9,13 +10,26 @@ COPY package*.json ./
|
||||||
|
|
||||||
# 4. Installiere Abhängigkeiten
|
# 4. Installiere Abhängigkeiten
|
||||||
RUN npm install
|
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
|
# 5. Kopiere den Rest des Codes
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# 6. Kompiliere TypeScript (optional, falls ts-node nicht genutzt wird)
|
# 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
|
# 7. Starte das TypeScript-Skript mit ts-node
|
||||||
CMD ["npx", "ts-node", "mailsender.ts"]
|
#CMD ["npx", "ts-node", "mailsender.ts"]
|
||||||
|
CMD ["npx", "ts-node", "broker.ts"]
|
33
broker.ts
33
broker.ts
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
exec('iching divine', (error, stdout, stderr) => {
|
exec('iching divine', (error, stdout, stderr) => {
|
||||||
|
|
||||||
console.log(`Beginn`);
|
console.log(`Beginn`);
|
||||||
|
@ -17,6 +17,33 @@ exec('iching divine', (error, stdout, stderr) => {
|
||||||
return;
|
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" <test@example.com>',
|
||||||
|
to: "Christopher.Hase@telekom.com;test@mailhog.local",
|
||||||
|
subject: "Hallo von MailHog",
|
||||||
|
text: content,
|
||||||
|
html: "<p> ${content} </p>"
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("E-Mail gesendet: ", info.messageId);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Fehler beim Senden der E-Mail:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue