Skip to content

Commit

Permalink
Switched to msmtp #61 #31 (#63)
Browse files Browse the repository at this point in the history
Add support for sending emails based on #61 

Co-authored-by: ckulka <ckulka@wlgore.com>
  • Loading branch information
ckulka and ckulka authored Dec 23, 2022
1 parent 7fe3a4e commit 5b2d767
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions apache-php8.0.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions apache.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions docs/email-guide.md
Original file line number Diff line number Diff line change
@@ -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 <smtp 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 <smtp host>
port 587
from baikal@example.com
user <user>
password <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 <user>@gmail.com
user <user>
password <password>
```
See [examples/docker-compose.sendmail-gmail.yaml](../examples/docker-compose.email-gmail.yaml) for a starter template.
29 changes: 29 additions & 0 deletions examples/docker-compose.email-gmail.yaml
Original file line number Diff line number Diff line change
@@ -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 <user>@gmail.com
user <user>
password <password>
ports:
- "80:80"
volumes:
- config:/var/www/baikal/config
- data:/var/www/baikal/Specific

volumes:
config:
data:
29 changes: 29 additions & 0 deletions examples/docker-compose.email.yaml
Original file line number Diff line number Diff line change
@@ -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 host>
port 587
from baikal@example.com
user <user>
password <password>
ports:
- "80:80"
volumes:
- config:/var/www/baikal/config
- data:/var/www/baikal/Specific

volumes:
config:
data:
11 changes: 11 additions & 0 deletions files/docker-entrypoint.d/50-start-msmtp.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion nginx-php8.0.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nginx.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b2d767

Please sign in to comment.