Skip to content

Commit

Permalink
Send processed emails to opensmtpd
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlgo11 committed Jan 9, 2025
1 parent cd8b17f commit 700fbaf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions outbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM node:20-alpine
WORKDIR /app
COPY . /app/
COPY smtpd.conf /etc/smtpd/smtpd.conf
RUN apk upgrade -U; apk add --no-cache opensmtpd
RUN npm i --omit=dev
COPY --chmod=500 entrypoint.sh /entrypoint
ENTRYPOINT ["/entrypoint"]
CMD ["src/server.js"]
18 changes: 18 additions & 0 deletions outbox/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

SPOOL=" /var/spool/smtpd"

chmod 711 "$SPOOL"

chmod 770 "$SPOOL/offline"
chown 0:102 "$SPOOL/offline"

chmod 700 "$SPOOL/purge"
chown 101:0 "$SPOOL/purge"

chmod 700 "$SPOOL/queue"
chown 101:0 "$SPOOL/queue"

smtpd -d -v -P mda &

node "$*"
3 changes: 3 additions & 0 deletions outbox/smtpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
listen on lo
action "relay" relay
match from local for any action "relay"
5 changes: 5 additions & 0 deletions outbox/src/handlers/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import redis from '../services/redis.js';
import { Response } from '@carlgo11/smtp-server';
import signMessage from '../services/dkim.js';
import fs from 'fs/promises';
import { promisify } from 'util';
import { execFile } from 'child_process';
const execFileAsync = promisify(execFile);

export default async function handleData(message, session) {
const from = session.mailFrom;
Expand Down Expand Up @@ -51,6 +54,8 @@ export default async function handleData(message, session) {
}

await fs.writeFile(`/tmp/${email.id}.eml`, email.full_email());

await execFileAsync(`cat /tmp/${email.id} | sendmail -t -v -f ${from}`);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions outbox/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const server = Server({
key: fs.readFileSync(process.env.OUTBOX_TLS_KEY_PATH),
cert: fs.readFileSync(process.env.OUTBOX_TLS_CERT_PATH),
handshakeTimeout: 5000,
minVersion: 'TLSv1.3',
maxVersion: 'TLSv1.3',
ALPNProtocols: ['h2'],
minVersion: process.env.OUTBOX_TLS_MIN_VERSION || process.env.TLS_MIN_VERSION,
maxVersion: process.env.OUTBOX_TLS_MAX_VERSION || process.env.TLS_MAX_VERSION,
requestOCSP: true,
},
logLevel: 'DEBUG',
logLevel: process.env.LOG_LEVEL || 'INFO',
extensions: ['ENHANCEDSTATUSCODES', 'PIPELINING', 'AUTH PLAIN', '8BITMIME'],
onMAILFROM: handleMail,
onDATA: handleData,
Expand Down

0 comments on commit 700fbaf

Please sign in to comment.