From 97ae973211f4e7fbca7972de4b3e5b89735b97d8 Mon Sep 17 00:00:00 2001 From: BhasherBEL Date: Sun, 24 Dec 2023 13:05:03 +0100 Subject: [PATCH] Kill-the-newsletter --- builds/kill-the-newsletter/Dockerfile | 2 +- builds/kill-the-newsletter/docker.js | 66 +------------------ .../docker-compose.kill-the-newsletter.yaml | 23 +++++++ 3 files changed, 25 insertions(+), 66 deletions(-) create mode 100644 bxl-shp/apps/docker-compose.kill-the-newsletter.yaml diff --git a/builds/kill-the-newsletter/Dockerfile b/builds/kill-the-newsletter/Dockerfile index 45acd52..8f2ae62 100644 --- a/builds/kill-the-newsletter/Dockerfile +++ b/builds/kill-the-newsletter/Dockerfile @@ -3,7 +3,7 @@ FROM debian:12 WORKDIR /kill-the-newsletter RUN apt update -RUN apt install -y wget +RUN apt install -y wget npm RUN wget https://github.com/leafac/kill-the-newsletter/releases/download/v1.0.1/kill-the-newsletter--linux--v1.0.1.tgz diff --git a/builds/kill-the-newsletter/docker.js b/builds/kill-the-newsletter/docker.js index a13d841..41df775 100644 --- a/builds/kill-the-newsletter/docker.js +++ b/builds/kill-the-newsletter/docker.js @@ -20,68 +20,4 @@ module.exports = async (require) => { console.log("Email server started"); }); - const Imap = require('imap'); - const nodemailer = require('nodemailer'); - const { simpleParser } = require('mailparser'); - - const imapConfig = { - user: process.env.IMAP_USER, - password: process.env.IMAP_PASSWORD, - host: process.env.IMAP_HOST, - port: process.env.IMAP_PORT, - tls: true - }; - - const smtpConfig = { - host: 'localhost', - port: 25, - secure: false - }; - - const imap = new Imap(imapConfig); - - function openInbox(cb) { - imap.openBox('INBOX', false, cb); - } - - function processEmails() { - openInbox((err, box) => { - if (err) throw err; - - imap.search(['UNSEEN'], (err, results) => { - if (err || !results || !results.length) { - console.log('No new emails'); - return; - } - - const f = imap.fetch(results, { bodies: '' }); - f.on('message', msg => { - msg.on('body', stream => { - simpleParser(stream, async (err, mail) => { - let transporter = nodemailer.createTransport(smtpConfig); - - await transporter.sendMail({ - from: mail.from, - to: mail.to, - subject: mail.subject, - text: mail.text, - html: mail.html - }); - - console.log('Email forwarded'); - }); - }); - }); - }); - }); - } - - imap.once('ready', () => { - processEmails(); - - setInterval(processEmails, (proess.env.INTERVAL || 300) * 1000); - }); - imap.once('error', err => console.error(err)); - imap.connect(); - -}; \ No newline at end of file +}; diff --git a/bxl-shp/apps/docker-compose.kill-the-newsletter.yaml b/bxl-shp/apps/docker-compose.kill-the-newsletter.yaml new file mode 100644 index 0000000..4a15dc3 --- /dev/null +++ b/bxl-shp/apps/docker-compose.kill-the-newsletter.yaml @@ -0,0 +1,23 @@ +services: + kill-the-newsletter: + container_name: kill-the-newsletter + image: registry.bhasher.com/kill-the-newsletter:latest + restart: unless-stopped + ports: + - 25:25/tcp + environment: + - TZ=Europe/Paris + - URL=https://kill-the-newsletter.bhasher.com + - SMTP=smtp://kill-the-newsletter.bhasher.com + - ADMIN_EMAIL=kill-the-newsletter.lan@bhasher.com + volumes: + - $DATA/kill-the-newsletter:/data + labels: + - "traefik.enable=true" + - "traefik.http.routers.kill-the-newsletter.rule=Host(`kill-the-newsletter.bhasher.com`)" + - "traefik.http.services.kill-the-newsletter.loadbalancer.server.port=80" + - "traefik.http.routers.kill-the-newsletter.tls=true" + - "traefik.http.routers.kill-the-newsletter.tls.certresolver=http" + - "traefik.http.routers.kill-the-newsletter.entrypoints=internalsecure" + networks: + - external