Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: crazy-max/.github/.github/actions/container-logs-check@main
with:
container_name: ${{ env.CONTAINER_NAME }}
log_check: "[services.d] done"
log_check: "starting SMTP session"
timeout: 120
-
name: Logs
Expand Down
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ RUN <<EOT
file /usr/bin/msmtpd
EOT

FROM crazymax/alpine-s6:${ALPINE_VERSION}-2.2.0.3

ENV S6_BEHAVIOUR_IF_STAGE2_FAILS="2" \
TZ="UTC" \
PUID="1500" \
PGID="1500"
FROM alpine:${ALPINE_VERSION}
ENV TZ=UTC

RUN apk --update --no-cache add \
bash \
ca-certificates \
gettext \
gnutls \
Expand All @@ -44,14 +39,19 @@ RUN apk --update --no-cache add \
shadow \
tzdata \
&& ln -sf /usr/bin/msmtp /usr/sbin/sendmail \
&& addgroup -g ${PGID} msmtpd \
&& adduser -D -H -u ${PUID} -G msmtpd -s /bin/sh msmtpd \
&& rm -rf /tmp/*
&& addgroup -g 1500 msmtpd \
&& adduser -D -H -u 1500 -G msmtpd -s /bin/sh msmtpd \
&& touch /etc/msmtprc \
&& chown msmtpd:msmtpd /etc/msmtprc

COPY --from=builder /usr/bin/msmtp* /usr/bin/
COPY rootfs /

EXPOSE 2500

USER msmtpd

CMD ["sh", "/entrypoint.sh"]

HEALTHCHECK --interval=10s --timeout=5s \
CMD echo EHLO localhost | nc 127.0.0.1 2500 | grep 250 || exit 1
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ docker buildx bake image-all

## Image

| Registry | Image |
|--------------------------------------------------------------------------------------------------|---------------------------------|
| [Docker Hub](https://hub.docker.com/r/crazymax/msmtpd/) | `crazymax/msmtpd` |
| [GitHub Container Registry](https://github.com/users/crazy-max/packages/container/package/msmtpd) | `ghcr.io/crazy-max/msmtpd` |
| Registry | Image |
|---------------------------------------------------------------------------------------------------|----------------------------|
| [Docker Hub](https://hub.docker.com/r/crazymax/msmtpd/) | `crazymax/msmtpd` |
| [GitHub Container Registry](https://github.com/users/crazy-max/packages/container/package/msmtpd) | `ghcr.io/crazy-max/msmtpd` |

Following platforms for this image are available:

Expand All @@ -78,8 +78,6 @@ linux/s390x
## Environment variables

* `TZ`: Timezone assigned to the container (default `UTC`)
* `PUID`: Daemon user id (default `1500`)
* `PGID`: Daemon group id (default `1500`)
* `SMTP_HOST`: SMTP relay server to send the mail to. **required**
* `SMTP_PORT`: Port that the SMTP relay server listens on. Default `25` or `465` if TLS.
* `SMTP_TLS`: Enable or disable TLS (also known as SSL) for secured connections (`on` or `off`).
Expand Down
2 changes: 0 additions & 2 deletions examples/compose/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ services:
protocol: tcp
environment:
- "TZ=Europe/Paris"
- "PUID=1500"
- "PGID=1500"
- "SMTP_HOST=smtp.gmail.com"
- "SMTP_PORT=587"
- "SMTP_TLS=on"
Expand Down
4 changes: 0 additions & 4 deletions examples/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ spec:
env:
- name: TZ
value: Europe/Paris
- name: PUID
value: "1500"
- name: PGID
value: "1500"
- name: SMTP_HOST
value: "smtp.gmail.com"
- name: SMTP_PORT
Expand Down
60 changes: 60 additions & 0 deletions rootfs/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
set -eu

file_env() {
var="$1"
file_var="${var}_FILE"
def="${2:-}"
eval "var_value=\${$var:-}"
eval "file_value=\${$file_var:-}"
if [ -n "$var_value" ] && [ -n "$file_value" ]; then
echo >&2 "error: both $var and $file_var are set (but are exclusive)"
exit 1
fi
if [ -n "$var_value" ]; then
value="$var_value"
elif [ -n "$file_value" ]; then
value="$(cat "$file_value")"
else
value="$def"
fi
export "$var=$value"
unset "$file_var"
}

if [ -z "${SMTP_HOST:-}" ]; then
echo >&2 "ERROR: SMTP_HOST must be defined"
exit 1
fi

echo "Creating configuration..."
cat > /etc/msmtprc <<EOF
account default
logfile -
syslog off
host ${SMTP_HOST}
EOF

file_env "SMTP_USER"
file_env "SMTP_PASSWORD"
if [ -n "${SMTP_PORT:-}" ]; then echo "port ${SMTP_PORT}" >> /etc/msmtprc; fi
if [ -n "${SMTP_TLS:-}" ]; then echo "tls ${SMTP_TLS}" >> /etc/msmtprc; fi
if [ -n "${SMTP_STARTTLS:-}" ]; then echo "tls_starttls ${SMTP_STARTTLS}" >> /etc/msmtprc; fi
if [ -n "${SMTP_TLS_CHECKCERT:-}" ]; then echo "tls_certcheck ${SMTP_TLS_CHECKCERT}" >> /etc/msmtprc; fi
if [ -n "${SMTP_AUTH:-}" ]; then echo "auth ${SMTP_AUTH}" >> /etc/msmtprc; fi
if [ -n "${SMTP_USER:-}" ]; then echo "user ${SMTP_USER}" >> /etc/msmtprc; fi
if [ -n "${SMTP_PASSWORD:-}" ]; then echo "password ${SMTP_PASSWORD}" >> /etc/msmtprc; fi
if [ -n "${SMTP_DOMAIN:-}" ]; then echo "domain ${SMTP_DOMAIN}" >> /etc/msmtprc; fi
if [ -n "${SMTP_FROM:-}" ]; then echo "from ${SMTP_FROM}" >> /etc/msmtprc; fi
if [ -n "${SMTP_ALLOW_FROM_OVERRIDE:-}" ]; then echo "allow_from_override ${SMTP_ALLOW_FROM_OVERRIDE}" >> /etc/msmtprc; fi
if [ -n "${SMTP_SET_FROM_HEADER:-}" ]; then echo "set_from_header ${SMTP_SET_FROM_HEADER}" >> /etc/msmtprc; fi
if [ -n "${SMTP_SET_DATE_HEADER:-}" ]; then echo "set_date_header ${SMTP_SET_DATE_HEADER}" >> /etc/msmtprc; fi
if [ -n "${SMTP_REMOVE_BCC_HEADERS:-}" ]; then echo "remove_bcc_headers ${SMTP_REMOVE_BCC_HEADERS}" >> /etc/msmtprc; fi
if [ -n "${SMTP_UNDISCLOSED_RECIPIENTS:-}" ]; then echo "undisclosed_recipients ${SMTP_UNDISCLOSED_RECIPIENTS}" >> /etc/msmtprc; fi
if [ -n "${SMTP_DSN_NOTIFY:-}" ]; then echo "dsn_notify ${SMTP_DSN_NOTIFY}" >> /etc/msmtprc; fi
if [ -n "${SMTP_DSN_RETURN:-}" ]; then echo "dsn_return ${SMTP_DSN_RETURN}" >> /etc/msmtprc; fi
unset SMTP_USER
unset SMTP_PASSWORD

echo "Starting msmtpd..."
exec msmtpd --interface=0.0.0.0 --port=2500 --log=/proc/self/fd/2 "--command=/usr/bin/msmtp -f %F"
5 changes: 0 additions & 5 deletions rootfs/etc/cont-init.d/00-fix-logs.sh

This file was deleted.

12 changes: 0 additions & 12 deletions rootfs/etc/cont-init.d/01-fix-uidgid.sh

This file was deleted.

82 changes: 0 additions & 82 deletions rootfs/etc/cont-init.d/02-config.sh

This file was deleted.

11 changes: 0 additions & 11 deletions rootfs/etc/cont-init.d/03-create-service.sh

This file was deleted.

2 changes: 0 additions & 2 deletions test/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ services:
protocol: tcp
environment:
- "TZ=Europe/Paris"
- "PUID=1500"
- "PGID=1500"
- "SMTP_HOST=smtp.foo.bar"
restart: always