Skip to content

Commit 412c993

Browse files
committed
relay smtp
1 parent 755e24c commit 412c993

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

.github/workflows/docker-image.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,22 @@ jobs:
100100
labels: ${{ steps.metaClient.outputs.labels }}
101101
platforms: linux/amd64
102102

103+
# Process for the `relay-smtpt` subfolder
104+
- name: Extract metadata (tags, labels) for relay-smtp
105+
id: metaSmtp
106+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
107+
with:
108+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/relay-smtp
109+
tags: |
110+
# set latest tag for default branch
111+
type=raw,value=latest,enable={{is_default_branch}}
112+
113+
- name: Build and push Docker image (relay-smtp)
114+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
115+
with:
116+
context: ./relay-smtp
117+
push: true
118+
tags: ${{ steps.metaSmtp.outputs.tags }}
119+
labels: ${{ steps.metaSmtp.outputs.labels }}
120+
platforms: linux/amd64
121+

smtp-relay/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM alpine:3.21
2+
3+
LABEL maintainer="aa@libertech.fr"
4+
5+
ARG BUILD_DATE
6+
ARG NAME
7+
ARG VCS_REF
8+
ARG VERSION
9+
10+
LABEL org.label-schema.schema-version="1.0" \
11+
org.label-schema.build-date=$BUILD_DATE \
12+
org.label-schema.name=$NAME \
13+
org.label-schema.vcs-ref=$VCS_REF \
14+
org.label-schema.vcs-url="https://github.com/libertech-fr/postfix" \
15+
org.label-schema.version=$VERSION
16+
17+
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
18+
19+
RUN apk add --no-cache bash openssl postfix
20+
COPY postfix_init.sh /postfix_init.sh
21+
RUN chmod 755 /postfix_init.sh
22+
23+
EXPOSE 25
24+
25+
CMD ["/postfix_init.sh"]
26+
27+
HEALTHCHECK --interval=15s --timeout=10s --retries=3 CMD postfix status || exit 1
28+

smtp-relay/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Relay SMTP
2+
3+
## docker-compose.yml
4+
ervices:
5+
smtp:
6+
#image: rapidfort/postfix-ib:latest
7+
build: .
8+
container_name: smtp
9+
ports:
10+
- "25:25"
11+
environment:
12+
- POSTFIX_RELAYHOST_PORT=25
13+
- POSTFIX_RELAYHOST=MONRELAY
14+
- POSTFIX_TLS=true
15+
- POSTFIX_MYNETWORKS=10.0.0.0/8
16+
- POSTFIX_TLS=true
17+
- POSTFIX_SASL_AUTH=USERNAME:PASSWORD
18+
19+
## Variables d'environements
20+
21+
* POSTFIX_RELAYHOST_PORT = Port du relay SMTP
22+
* POSTFIX_RELAYHOST = FDQN ou IP du relay SMTP
23+
* POSTFIX_MYNETWORKS = Reseaux autorisés à poster
24+
* POSTFIX_TLS = Connection au relay en TLS
25+
* POSTFIX_SASL_AUTH = Credentials du relay sous la forme username:password
26+

smtp-relay/docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
smtp:
3+
#image: rapidfort/postfix-ib:latest
4+
build: .
5+
container_name: smtp
6+
ports:
7+
- "25:25"
8+
environment:
9+
- POSTFIX_RELAYHOST_PORT=25
10+
- POSTFIX_MYNETWORKS=10.0.0.0/8

smtp-relay/postfix_init.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
#
3+
4+
set -eo pipefail
5+
6+
echo "Configuring postfix with any environment variables that are set"
7+
8+
if [[ -n "${POSTFIX_MYNETWORKS}" ]]; then
9+
echo "Setting custom 'mynetworks' to '${POSTFIX_MYNETWORKS}'"
10+
postconf mynetworks="${POSTFIX_MYNETWORKS}"
11+
else
12+
echo "Set 'mynetworks' to default"
13+
postconf mynetworks="127.0.0.1/32 172.0.0.0/8"
14+
fi
15+
16+
if [[ -n "${POSTFIX_RELAYHOST}" ]]; then
17+
echo "Setting custom 'relayhost' to '${POSTFIX_RELAYHOST}'"
18+
postconf relayhost="[${POSTFIX_RELAYHOST}]:${POSTFIX_RELAYHOST_PORT}"
19+
else
20+
echo "Set 'relayhost' to default (unset)"
21+
postconf -# relayhost
22+
fi
23+
24+
echo "Disable chroot for the smtp service"
25+
postconf -F smtp/inet/chroot=n
26+
postconf -F smtp/unix/chroot=n
27+
28+
if [[ "${POSTFIX_INETPROTOCOLS}" = "all" ]]; then
29+
echo "Enabling IPv4 and IPv6"
30+
postconf inet_protocols="all"
31+
elif [[ "${POSTFIX_INETPROTOCOLS}" = "ipv6" ]]; then
32+
echo "Enabling IPv6"
33+
postconf inet_protocols="ipv6"
34+
elif [[ "${POSTFIX_INETPROTOCOLS}" = "ipv4, ipv6" ]]; then
35+
echo "Enabling IPv4 and IPv6"
36+
postconf inet_protocols="all"
37+
elif [[ "${POSTFIX_INETPROTOCOLS}" = "ipv4" ]]; then
38+
echo "Enabling IPv4"
39+
postconf inet_protocols="ipv4"
40+
else
41+
echo "Enabling IPv4"
42+
postconf inet_protocols="ipv4"
43+
fi
44+
45+
#echo "Disable ipv6"
46+
#postconf inet_protocols="ipv4"
47+
48+
if [[ "${POSTFIX_TLS}" = "true" ]]; then
49+
echo "Configuring TLS"
50+
postconf smtp_tls_CAfile="/etc/ssl/certs/ca-certificates.crt"
51+
postconf smtp_tls_security_level="encrypt"
52+
postconf smtp_use_tls="yes"
53+
postconf smtp_tls_wrappermode="yes"
54+
fi
55+
56+
if [[ -n "${POSTFIX_SASL_AUTH}" ]]; then
57+
echo "Configuring SASL Auth"
58+
if [[ -z "${POSTFIX_RELAYHOST}" || -z "${POSTFIX_TLS}" ]]; then
59+
echo "Please set 'POSTFIX_RELAYHOST' AND 'POSTFIX_TLS' before attempting to enable SSL auth."
60+
exit 1
61+
fi
62+
63+
postconf smtp_sasl_auth_enable="yes"
64+
postconf smtp_sasl_password_maps="lmdb:/etc/postfix/sasl_passwd"
65+
postconf smtp_sasl_security_options="noanonymous"
66+
postconf smtp_tls_note_starttls_offer="yes"
67+
# generate the SASL password map
68+
echo "${POSTFIX_RELAYHOST} ${POSTFIX_SASL_AUTH}" > /etc/postfix/sasl_passwd
69+
70+
# generate a .db file and clean it up
71+
postmap lmdb:/etc/postfix/sasl_passwd && rm /etc/postfix/sasl_passwd
72+
73+
# set permissions
74+
chmod 600 /etc/postfix/sasl_passwd.lmdb
75+
fi
76+
postconf maillog_file=/var/log/postfix.log
77+
postconf maillog_file_permissions=0644
78+
79+
echo "Starting postfix"
80+
postfix start-fg

0 commit comments

Comments
 (0)