From 5b2d7673d52c2936047a03ea12d2b074cfbab853 Mon Sep 17 00:00:00 2001 From: Cyrill Kulka Date: Thu, 22 Dec 2022 19:08:52 -0500 Subject: [PATCH] Switched to msmtp #61 #31 (#63) Add support for sending emails based on #61 Co-authored-by: ckulka --- README.md | 1 + apache-php8.0.dockerfile | 8 ++- apache.dockerfile | 8 ++- docs/email-guide.md | 72 +++++++++++++++++++++ examples/docker-compose.email-gmail.yaml | 29 +++++++++ examples/docker-compose.email.yaml | 29 +++++++++ files/docker-entrypoint.d/50-start-msmtp.sh | 11 ++++ nginx-php8.0.dockerfile | 2 +- nginx.dockerfile | 2 +- 9 files changed, 154 insertions(+), 8 deletions(-) create mode 100644 docs/email-guide.md create mode 100644 examples/docker-compose.email-gmail.yaml create mode 100644 examples/docker-compose.email.yaml create mode 100755 files/docker-entrypoint.d/50-start-msmtp.sh diff --git a/README.md b/README.md index f38c7b5..2f3239a 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ If you want to use local folders instead of Docker volumes, see [examples/docker You can find more installation and configuration guides here: +- [Email Guide](https://github.com/ckulka/baikal-docker/blob/master/docs/email-guide.md) - [SSL Certificate Guide](https://github.com/ckulka/baikal-docker/blob/master/docs/ssl-certificates-guide.md) - [systemd Guide](https://github.com/ckulka/baikal-docker/blob/master/docs/systemd-guide.md) - [Unraid Installation Guide](https://github.com/ckulka/baikal-docker/blob/master/docs/unraid-installation-guide.md) diff --git a/apache-php8.0.dockerfile b/apache-php8.0.dockerfile index d386ac8..29a732e 100644 --- a/apache-php8.0.dockerfile +++ b/apache-php8.0.dockerfile @@ -16,9 +16,11 @@ LABEL website="http://sabre.io/baikal/" # Install Baikal and required dependencies COPY --from=builder --chown=www-data:www-data baikal /var/www/baikal -RUN apt-get update &&\ - apt-get install -y libcurl4-openssl-dev sendmail &&\ - rm -rf /var/lib/apt/lists/* &&\ +RUN apt-get update &&\ + apt-get install -y \ + libcurl4-openssl-dev \ + msmtp msmtp-mta &&\ + rm -rf /var/lib/apt/lists/* &&\ docker-php-ext-install curl pdo pdo_mysql # Configure Apache + HTTPS diff --git a/apache.dockerfile b/apache.dockerfile index 0136874..c40c95d 100644 --- a/apache.dockerfile +++ b/apache.dockerfile @@ -16,9 +16,11 @@ LABEL website="http://sabre.io/baikal/" # Install Baikal and required dependencies COPY --from=builder --chown=www-data:www-data baikal /var/www/baikal -RUN apt-get update &&\ - apt-get install -y libcurl4-openssl-dev sendmail &&\ - rm -rf /var/lib/apt/lists/* &&\ +RUN apt-get update &&\ + apt-get install -y \ + libcurl4-openssl-dev \ + msmtp msmtp-mta &&\ + rm -rf /var/lib/apt/lists/* &&\ docker-php-ext-install curl pdo pdo_mysql # Configure Apache + HTTPS diff --git a/docs/email-guide.md b/docs/email-guide.md new file mode 100644 index 0000000..05ff9bd --- /dev/null +++ b/docs/email-guide.md @@ -0,0 +1,72 @@ +# Email Guide + +This guide outlines the email configuration so that you can send out email invitations. Many thanks to [@philippneugebauer](https://github.com/philippneugebauer), [@vaskozl](https://github.com/vaskozl), [ahgraber](https://github.com/ahgraber), and everyone in [#61](https://github.com/ckulka/baikal-docker/discussions/61) for contributing. + +In order to send out emails, you need a working SMTP service - you can host your own or rely on a service such as [Gmail](https://support.google.com/mail/answer/7126229?hl=en#zippy=%2Cstep-change-smtp-other-settings-in-your-email-client). + +The entire email configuration is stored in the `MSMTPRC` environment variable. + +## Generic SMTP server + +If you have an SMTP server without security in place, i.e. no authentication or SSL/TLS/STARTTLS, then you only have to configure the SMTP server name. Needless to say it's highly recommended to have authentication and TLS in place. + +```yaml +services: + baikal: + image: ckulka/baikal:nginx + environment: + MSMTPRC: | + defaults + account default + host + port 25 +``` + +If you have TLS and authentication in place, add the following configuration parameters: + +```yaml +services: + baikal: + image: ckulka/baikal:nginx + restart: always + environment: + MSMTPRC: | + defaults + auth on + tls on + tls_trust_file /etc/ssl/certs/ca-certificates.crt + account default + host + port 587 + from baikal@example.com + user + password +``` + +See [examples/docker-compose.email.yaml](../examples/docker-compose.email.yaml) for a starter template. + +## Gmail + +If you use Gmail as your SMTP server, you have to first allow less secure apps (sendmail) to use Gmail, see [Less secure apps & your Google Account](https://support.google.com/accounts/answer/6010255?hl=en#zippy=). + +Once that is done, use the following configuration: + +```yaml +services: + baikal: + image: ckulka/baikal:nginx + environment: + MSMTPRC: | + defaults + auth on + tls on + tls_trust_file /etc/ssl/certs/ca-certificates.crt + account default + host smtp.gmail.com + port 587 + from @gmail.com + user + password +``` + +See [examples/docker-compose.sendmail-gmail.yaml](../examples/docker-compose.email-gmail.yaml) for a starter template. diff --git a/examples/docker-compose.email-gmail.yaml b/examples/docker-compose.email-gmail.yaml new file mode 100644 index 0000000..e092ea6 --- /dev/null +++ b/examples/docker-compose.email-gmail.yaml @@ -0,0 +1,29 @@ +# Docker Compose file for a Baikal server +# See https://github.com/ckulka/baikal-docker/blob/master/docs/email-guide.md + +version: "2" +services: + baikal: + image: ckulka/baikal:nginx + restart: always + environment: + MSMTPRC: | + defaults + auth on + tls on + tls_trust_file /etc/ssl/certs/ca-certificates.crt + account default + host smtp.gmail.com + port 587 + from @gmail.com + user + password + ports: + - "80:80" + volumes: + - config:/var/www/baikal/config + - data:/var/www/baikal/Specific + +volumes: + config: + data: diff --git a/examples/docker-compose.email.yaml b/examples/docker-compose.email.yaml new file mode 100644 index 0000000..85587d7 --- /dev/null +++ b/examples/docker-compose.email.yaml @@ -0,0 +1,29 @@ +# Docker Compose file for a Baikal server +# See https://github.com/ckulka/baikal-docker/blob/master/docs/email-guide.md + +version: "2" +services: + baikal: + image: ckulka/baikal:nginx + restart: always + environment: + MSMTPRC: | + defaults + auth on + tls on + tls_trust_file /etc/ssl/certs/ca-certificates.crt + account default + host + port 587 + from baikal@example.com + user + password + ports: + - "80:80" + volumes: + - config:/var/www/baikal/config + - data:/var/www/baikal/Specific + +volumes: + config: + data: diff --git a/files/docker-entrypoint.d/50-start-msmtp.sh b/files/docker-entrypoint.d/50-start-msmtp.sh new file mode 100755 index 0000000..8e7bbd7 --- /dev/null +++ b/files/docker-entrypoint.d/50-start-msmtp.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# See https://github.com/ckulka/baikal-docker/discussions/61 + +# Insert sendmail mailer definitions +if [ ! -z ${MSMTPRC+x} ] +then + echo "$MSMTPRC" > /etc/msmtprc + chown root:msmtp /etc/msmtprc + chmod 640 /etc/msmtprc +fi diff --git a/nginx-php8.0.dockerfile b/nginx-php8.0.dockerfile index 5d91a7f..d36b62d 100644 --- a/nginx-php8.0.dockerfile +++ b/nginx-php8.0.dockerfile @@ -29,7 +29,7 @@ RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg php8.0-sqlite3 \ php8.0-xml \ sqlite3 \ - sendmail &&\ + msmtp msmtp-mta &&\ rm -rf /var/lib/apt/lists/* &&\ sed -i 's/www-data/nginx/' /etc/php/8.0/fpm/pool.d/www.conf &&\ sed -i 's/^listen = .*/listen = \/var\/run\/php-fpm.sock/' /etc/php/8.0/fpm/pool.d/www.conf diff --git a/nginx.dockerfile b/nginx.dockerfile index 9a3d55b..13ac78e 100644 --- a/nginx.dockerfile +++ b/nginx.dockerfile @@ -29,7 +29,7 @@ RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg php8.1-sqlite3 \ php8.1-xml \ sqlite3 \ - sendmail &&\ + msmtp msmtp-mta &&\ rm -rf /var/lib/apt/lists/* &&\ sed -i 's/www-data/nginx/' /etc/php/8.1/fpm/pool.d/www.conf &&\ sed -i 's/^listen = .*/listen = \/var\/run\/php-fpm.sock/' /etc/php/8.1/fpm/pool.d/www.conf