Kill-the-newsletter
This commit is contained in:
parent
43ecf1a788
commit
97ae973211
|
@ -3,7 +3,7 @@ FROM debian:12
|
||||||
WORKDIR /kill-the-newsletter
|
WORKDIR /kill-the-newsletter
|
||||||
|
|
||||||
RUN apt update
|
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
|
RUN wget https://github.com/leafac/kill-the-newsletter/releases/download/v1.0.1/kill-the-newsletter--linux--v1.0.1.tgz
|
||||||
|
|
||||||
|
|
|
@ -20,68 +20,4 @@ module.exports = async (require) => {
|
||||||
console.log("Email server started");
|
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();
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -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
|
Loading…
Reference in New Issue