summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Rakel <sebastian@devunit.eu>2018-08-29 10:00:54 +0200
committerSebastian Rakel <sebastian@devunit.eu>2018-08-29 13:04:34 +0200
commitece8a5d7e499f99c2171edbcf5e4dde455541912 (patch)
tree8c676dbf5d6fc029a068f2a6b7124e53b80dea55
parenteba4933c6d529ec76048d21af8218be90fd6505b (diff)
Use msmtp to send mail in docker container
To send mails in the docker container we need to configure php to use a smtp client and provide smtp credentials to the docker container
-rw-r--r--Dockerfile4
-rw-r--r--docker/README.md5
-rw-r--r--docker/docker-compose.yml4
-rwxr-xr-xdocker/filebin_starter.sh18
4 files changed, 30 insertions, 1 deletions
diff --git a/Dockerfile b/Dockerfile
index 2645ec764..6a038898f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,7 @@
FROM alpine:edge
MAINTAINER Sebastian Rakel <sebastian@devunit.eu>
-RUN apk add --no-cache bash php7 py-pygments py2-pip imagemagick php7-gd nodejs composer php7-pdo_mysql php7-exif php7-ctype php7-session git php7-fileinfo
+RUN apk add --no-cache bash php7 py-pygments py2-pip imagemagick php7-gd nodejs composer php7-pdo_mysql php7-exif php7-ctype php7-session git php7-fileinfo msmtp
ENV FILEBIN_HOME_DIR /var/lib/filebin
ENV FILEBIN_DIR $FILEBIN_HOME_DIR/filebin
@@ -13,6 +13,8 @@ RUN chown filebin: -R $FILEBIN_HOME_DIR
RUN pip install ansi2html
+RUN sed -i 's+.*sendmail_path =.*+sendmail_path = "/usr/bin/msmtp -C ${FILEBIN_HOME_DIR}/msmtprc --logfile ${FILEBIN_HOME_DIR}/msmtp.log -a filebinmail -t"+' /etc/php7/php.ini
+
USER filebin
ADD docker/filebin_starter.sh $FILEBIN_HOME_DIR
diff --git a/docker/README.md b/docker/README.md
index 32a812cda..775afa1de 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -23,6 +23,11 @@ The PHP webserver is listening on ```8080```
- **FB_CONTACT_NAME:** Contact Name
- **FB_CONTACT_MAIL:** Contact E-Mail (will be used as email for the first user)
+- **FB_SMTP_HOST:** Address of the SMTP Server
+- **FB_SMTP_PORT:** Port for SMTP Server (default 587)
+- **FB_SMTP_USER:** Username for SMTP Server (will also be used as mail from)
+- **FB_SMTP_PASSWORD:** Password for the SMTP Server Useraccount
+
## First User
The first user is **admin** with the password **admin**
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 03bc37f59..7450f6903 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -22,4 +22,8 @@ services:
- FB_DB_DATABASE=filebin
- FB_CONTACT_NAME=John Doe
- FB_CONTACT_MAIL=root@example.local
+ - FB_SMTP_HOST=localhost
+ - FB_SMTP_PORT=587
+ - FB_SMTP_USER=webmaster@example.invalid
+ - FB_SMTP_PASSWORD=mysecretpassword
diff --git a/docker/filebin_starter.sh b/docker/filebin_starter.sh
index 7f0b70d85..66f9a8b03 100755
--- a/docker/filebin_starter.sh
+++ b/docker/filebin_starter.sh
@@ -2,12 +2,29 @@
#set -euo pipefail
+function set_mail_config() {
+cat <<EOF > ${FILEBIN_HOME_DIR}/msmtprc
+account filebinmail
+tls on
+tls_certcheck off
+auth on
+host ${FB_SMTP_HOST}
+port ${FB_SMTP_PORT}
+user ${FB_SMTP_USER}
+from ${FB_SMTP_USER}
+password ${FB_SMTP_PASSWORD}
+EOF
+
+chmod 600 ${FILEBIN_HOME_DIR}/msmtprc
+}
+
function set_config() {
FB_ENCRYPTION_KEY=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32`
cat <<EOF >${FILEBIN_DIR}/application/config/config-local.php
<?php
\$config['base_url'] = 'http://127.0.0.1:8080/';
\$config['encryption_key'] = '${FB_ENCRYPTION_KEY}';
+\$config['email_from'] = '${FB_SMTP_USER}';
EOF
}
@@ -53,6 +70,7 @@ if [[ ! -e $FILEBIN_DIR/application/config/config-local.php ]]; then
set_config
set_database_config
+ set_mail_config
CONTACT_INFO_FILE=${FILEBIN_DIR}/data/local/contact-info.php
cp $FILEBIN_DIR/data/local/examples/contact-info.php ${CONTACT_INFO_FILE}