From dc04397618084647989ab75608a3c90d396de6b2 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Mon, 29 Apr 2019 13:47:16 +0200 Subject: [PATCH] Set SMTP via environment vars. (#698) * Set SMTP via environment vars. Signed-off-by: Rodrigo Aguilera * Add SMTP instructions to the readme. Signed-off-by: Rodrigo Aguilera * Run update.sh for 16.0 release. Signed-off-by: Rodrigo Aguilera --- .config/smtp.config.php | 15 +++++++++++++++ 14.0/apache/config/smtp.config.php | 15 +++++++++++++++ 14.0/fpm-alpine/config/smtp.config.php | 15 +++++++++++++++ 14.0/fpm/config/smtp.config.php | 15 +++++++++++++++ 15.0/apache/config/smtp.config.php | 15 +++++++++++++++ 15.0/fpm-alpine/config/smtp.config.php | 15 +++++++++++++++ 15.0/fpm/config/smtp.config.php | 15 +++++++++++++++ 16.0/apache/config/smtp.config.php | 15 +++++++++++++++ 16.0/fpm-alpine/config/smtp.config.php | 15 +++++++++++++++ 16.0/fpm/config/smtp.config.php | 15 +++++++++++++++ README.md | 16 +++++++++++++++- 11 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 .config/smtp.config.php create mode 100644 14.0/apache/config/smtp.config.php create mode 100644 14.0/fpm-alpine/config/smtp.config.php create mode 100644 14.0/fpm/config/smtp.config.php create mode 100644 15.0/apache/config/smtp.config.php create mode 100644 15.0/fpm-alpine/config/smtp.config.php create mode 100644 15.0/fpm/config/smtp.config.php create mode 100644 16.0/apache/config/smtp.config.php create mode 100644 16.0/fpm-alpine/config/smtp.config.php create mode 100644 16.0/fpm/config/smtp.config.php diff --git a/.config/smtp.config.php b/.config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/.config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/14.0/apache/config/smtp.config.php b/14.0/apache/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/14.0/apache/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/14.0/fpm-alpine/config/smtp.config.php b/14.0/fpm-alpine/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/14.0/fpm-alpine/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/14.0/fpm/config/smtp.config.php b/14.0/fpm/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/14.0/fpm/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/15.0/apache/config/smtp.config.php b/15.0/apache/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/15.0/apache/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/15.0/fpm-alpine/config/smtp.config.php b/15.0/fpm-alpine/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/15.0/fpm-alpine/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/15.0/fpm/config/smtp.config.php b/15.0/fpm/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/15.0/fpm/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/16.0/apache/config/smtp.config.php b/16.0/apache/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/16.0/apache/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/16.0/fpm-alpine/config/smtp.config.php b/16.0/fpm-alpine/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/16.0/fpm-alpine/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/16.0/fpm/config/smtp.config.php b/16.0/fpm/config/smtp.config.php new file mode 100644 index 00000000..59f1eaa1 --- /dev/null +++ b/16.0/fpm/config/smtp.config.php @@ -0,0 +1,15 @@ + 'smtp', + 'mail_smtphost' => getenv('SMTP_HOST'), + 'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25), + 'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '', + 'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'), + 'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN', + 'mail_smtpname' => getenv('SMTP_NAME') ?: '', + 'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '', + 'mail_from_address' => getenv('MAIL_FROM_ADDRESS'), + 'mail_domain' => getenv('MAIL_DOMAIN'), + ); +} diff --git a/README.md b/README.md index 3f5f3b78..824d5da9 100644 --- a/README.md +++ b/README.md @@ -130,13 +130,27 @@ The install and update script is only triggered when a default command is used ( - `NEXTCLOUD_UPDATE` (default: _0_) -If you want to use Redis you have to create a seperate [Redis](https://hub.docker.com/_/redis/) container in your setup / in your docker-compose file. To inform Nextcloud about the Redis container add: +If you want to use Redis you have to create a separate [Redis](https://hub.docker.com/_/redis/) container in your setup / in your docker-compose file. To inform Nextcloud about the Redis container add: - `REDIS_HOST` (not set by default) Name of Redis container - `REDIS_HOST_PORT` (default: _6379_) Optional port for Redis, only use for external Redis servers that run on non-standard ports. The use of Redis is recommended to prevent file locking problems. See the examples for further instructions. +To use a external SMTP server you have to provide the conection details. To configure Nextcloud to use SMTP add: + +- `SMTP_HOST` (not set by default) hostname of the SMTP server +- `SMTP_SECURE` (empty by default) set to 'ssl' to use SSL on the connection. +- `SMTP_PORT` (default: _465_ for SSL and _25_ for non-secure connection) Optional port for SMTP connection. +- `SMTP_AUTHTYPE` (default: _LOGIN_) The method used for authentication. +- `SMTP_NAME` (empty by default) Username for the authentication. +- `SMTP_PASSWORD` (empty by default) Password for the authentication. +- `MAIL_FROM_ADDRESS` (not set by default) Use this address for the 'from' field in the mail envelopes sent by Nextcloud. +- `MAIL_DOMAIN` (not set by default) Set a different domain for the emails than the domain where Nextcloud is installed. + +Check the [Nextcloud documentation](https://docs.nextcloud.com/server/15/admin_manual/configuration_server/email_configuration.html) for other values to configure SMTP. + + # Running this image with docker-compose The easiest way to get a fully featured and functional setup is using a `docker-compose` file. There are too many different possibilities to setup your system, so here are only some examples what you have to look for.