From 80532ca493b4e82184e8902fa4535074996fe81b Mon Sep 17 00:00:00 2001 From: Jamie Nguyen Date: Wed, 11 Jul 2018 11:58:52 +0100 Subject: [PATCH] Initial commit --- Dockerfile | 18 +++++++++++++ README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 41 ++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..340ba23 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM debian:stretch-slim +MAINTAINER Bytemark Hosting "support@bytemark.co.uk" + +# Install exim4 +ENV DEBIAN_FRONTEND noninteractive +RUN set -ex; \ + apt-get update; \ + apt-get install -y exim4-daemon-light; \ + apt-get clean + +# Copy the main script. +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh + +# We expose exim on port 25. +EXPOSE 25/tcp + +ENTRYPOINT [ "docker-entrypoint.sh" ] +CMD [ "exim", "-bdf", "-v", "-q30m" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ee8665 --- /dev/null +++ b/README.md @@ -0,0 +1,64 @@ +# https://github.com/BytemarkHosting/docker-smtp + +## Maintained by: [Bytemark Hosting](https://www.bytemark.co.uk) + +This is the Git repo of the bytemark/smtp image. + +This image allows linked containers to send outgoing email. You can configure +it to send email directly to the recipient, or to act as a smart host and relay +mail to an intermediate server (eg, GMail, SendGrid). + +## Usage + +In the following examples, linked containers would be able to connect via SMTP +to hostname `mail` and port `25` to send outoing email. + +### Basic SMTP server + +In this example, linked containers can connect to hostname `mail` and port `25` +to send outgoing email. The SMTP container sends email out directly. + +``` +docker run --restart always --name mail -d bytemark/smtp +``` + +Via Docker Compose: + +``` + mail: + image: bytemark/smtp + restart: always +``` + +Optionally, set `MAILNAME` environment variable. (By default, Exim will use the +hostname of the container.) + +### SMTP smart host + +In this example, linked containers can connect to hostname `mail` and port `25` +to send outgoing email. The SMTP container acts as a smart host and relays mail +to an intermediate server server (eg, GMail, SendGrid). + +``` +docker run --restart always --name mail -d bytemark/smtp \ + -e RELAY_HOST=smtp.example.com \ + -e RELAY_PORT=587 \ + -e RELAY_USERNAME=alice@example.com \ + -e RELAY_PASSWORD=secretpassword +``` + +Via Docker Compose: + +``` + mail: + image: bytemark/smtp + restart: always + environment: + RELAY_HOST: smtp.example.com + RELAY_PORT: 587 + RELAY_USERNAME: alice@example.com + RELAY_PASSWORD: secretpassword +``` + +Optionally, set `MAILNAME` environment variable. (By default, Exim will use the +hostname of the container.) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..0ebd19e --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,41 @@ +#!/bin/sh +set -e +CONFDIR=/etc/exim4 + +# Set smarthost. +DC_EXIMCONFIG_CONFIGTYPE="internet" +if [ "x$RELAY_HOST" != "x" ]; then + DC_EXIMCONFIG_CONFIGTYPE="satellite" + DC_SMARTHOST="$RELAY_HOST::${RELAY_PORT:-25}" + if [ "x$RELAY_USERNAME" != "x" ] && [ "x$RELAY_PASSWORD" != "x" ]; then + printf '%s\n' "*:$RELAY_USERNAME:$RELAY_PASSWORD" > "$CONFDIR/passwd.client" + fi +fi + +# Write exim configuration. +cat << EOF > "$CONFDIR/update-exim4.conf.conf" +dc_eximconfig_configtype='$DC_EXIMCONFIG_CONFIGTYPE' +dc_other_hostnames='' +dc_local_interfaces='0.0.0.0' +dc_readhost='' +dc_relay_domains='*' +dc_minimaldns='false' +dc_relay_nets='0.0.0.0/0' +dc_smarthost='${DC_SMARTHOST:-}' +CFILEMODE='644' +dc_use_split_config='false' +dc_hide_mailname='true' +dc_mailname_in_oh='true' +dc_localdelivery='mail_spool' +EOF + +# Set primary_hostname. +if [ "x$MAILNAME" != "x" ]; then + printf '%s\n' "$MAILNAME" > /etc/mailname + printf '%s\n' "MAIN_HARDCODE_PRIMARY_HOSTNAME=$MAILNAME" >> "$CONFDIR/update-exim4.conf.conf" +fi + +# Apply exim configuration. +update-exim4.conf + +exec "$@"