Skip to content

Commit

Permalink
Merge pull request #10 from solidbunch/smtp-update
Browse files Browse the repository at this point in the history
Smtp update
  • Loading branch information
yuriipavlov authored Jun 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents c69f17b + 63fb815 commit f47f986
Showing 16 changed files with 95 additions and 108 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -114,6 +114,9 @@ replace:
pma:
docker compose -f docker-compose.build.yml run --service-ports --rm --build phpmyadmin

mailhog:
docker-compose -f docker-compose.build.yml run --service-ports --rm --name mailhog mailhog

log:
docker compose logs -f

37 changes: 32 additions & 5 deletions README.MD
Original file line number Diff line number Diff line change
@@ -192,14 +192,41 @@ make docker push

## Sending emails

Docker containers do not have a custom SMTP server. We use an SMTP relay service. You can set up an SMTP server
like Gmail, AWS, Sendinblue, Mailgun, etc, or use another server you like.
Mail is not routed by the Docker containers, you must use an SMTP external service to route your site's email.

Just edit sSMTP config block in your `.env.secret` file.
The reason that mail is not routed is that configuring mail to route from the proper domain on a server is often a headache. A further headache is actually getting mail delivered from an arbitrary IP. A third issue is that mail servers consume resources. A fourth issue is security. So for all these reasons we decided not to implement mail and instead delegate that task to various providers.

sSMTP config files `./docker/wordpress/config/ssmtp.conf.template` and `./docker/wordpress/config/revaliases.template` automatically loaded into the WordPress container
You can set up an SMTP service like Gmail, AWS SES, Sendinblue, Mailgun, etc., or use another server you like.

Just edit SMTP config block in your `.env.main` and `.env.secret` files.

`.env.main`:
```bash
# SMTP config
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587

# none|ssl|tls
SMTP_SECURE=tls
SMTP_DEBUG=0
```

`.env.secret`:
```bash
SMTP_USER=your_smtp_service_user_name
SMTP_PASS=your_smtp_service_user_password
```

Also, to debug Emails on local you can use [MailHog](https://github.com/mailhog/MailHog) service. Just run:

```bash
make mailhog
```

`.env.type.local` file already has mailhog connection settings.

This will run MailHog container, and you can access it on `your-app-domain.com:8025` URL.

See [an example](https://www.wordpressdocker.com/mailgun-ssmtp/) of ssmtp.conf

## Database management
### SSH tunnel options
18 changes: 18 additions & 0 deletions config/environment/.env.main
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ APP_CRON_IMAGE=ghcr.io/solidbunch/starter-kit-cron:1.5-alpine3.19
APP_COMPOSER_IMAGE=ghcr.io/solidbunch/starter-kit-composer:2.7
APP_NODE_IMAGE=ghcr.io/solidbunch/starter-kit-node:18-alpine3.19
APP_PHPMYADMIN_IMAGE=phpmyadmin:5.2-apache
APP_MAILHOG_IMAGE=mailhog/mailhog:v1.0.1

# Server capacity
WP_MEMORY_LIMIT=256M
@@ -75,3 +76,20 @@ SSH_TUNNEL_EXT_PORT=33061
# WARNING Do not run phpMyAdmin on production, it's not secure
PMA_EXT_PORT=8801
PMA_ARBITRARY=0

# SMTP config
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
# SMTP_USER and SMTP_PASS defined in .env.secret

# none|ssl|tls
SMTP_SECURE=tls
SMTP_FROM=
SMTP_NAME=

# 0 No debug output, default
# 1 Client commands
# 2 Client commands and server responses
# 3 As 2 plus connection status
# 4 Low-level data output, all messages.
SMTP_DEBUG=0
1 change: 1 addition & 0 deletions config/environment/.env.type.dev
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ APP_BA_WP_LOGIN=enable
APP_WP_BACKUP_ENABLE=1

# Debug
# Debug logging already defined in php.ini
WP_DEBUG=0
WP_DEBUG_DISPLAY=0
# Debug log connected as volume to ./logs/wordpress
16 changes: 16 additions & 0 deletions config/environment/.env.type.local
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ APP_BA_WP_LOGIN=disable
APP_WP_BACKUP_ENABLE=1

# Debug
# Debug logging already defined in php.ini
WP_DEBUG=0
WP_DEBUG_DISPLAY=0
# Debug log connected as volume to ./logs/wordpress
@@ -62,3 +63,18 @@ PHP_INI_SCAN_DIR=/usr/local/etc/php/local.d
# /dev/stderr and /dev/stdout follows logs to docker
APP_NGINX_ERROR_LOG=/dev/stderr
APP_NGINX_ACCESS_LOG=off

# SMTP config
SMTP_HOST=mailhog
SMTP_PORT=1025
# SMTP_USER and SMTP_PASS defined in .env.secret

# none|ssl|tls
SMTP_SECURE=none

# 0 No debug output, default
# 1 Client commands
# 2 Client commands and server responses
# 3 As 2 plus connection status
# 4 Low-level data output, all messages.
SMTP_DEBUG=4
1 change: 1 addition & 0 deletions config/environment/.env.type.prod
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ APP_BA_WP_LOGIN=enable
APP_WP_BACKUP_ENABLE=1

# Debug
# Debug logging already defined in php.ini
WP_DEBUG=0
WP_DEBUG_DISPLAY=0
# Debug log connected as volume to ./logs/wordpress
1 change: 1 addition & 0 deletions config/environment/.env.type.stage
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ APP_BA_WP_LOGIN=enable
APP_WP_BACKUP_ENABLE=1

# Debug
# Debug logging already defined in php.ini
WP_DEBUG=0
WP_DEBUG_DISPLAY=0
# Debug log connected as volume to ./logs/wordpress
2 changes: 1 addition & 1 deletion config/php/php.ini
Original file line number Diff line number Diff line change
@@ -1106,7 +1106,7 @@ pdo_mysql.default_socket=

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; https://php.net/sendmail-path
sendmail_path = /usr/sbin/ssmtp -t -i
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
8 changes: 0 additions & 8 deletions config/ssmtp/revaliases.template

This file was deleted.

35 changes: 0 additions & 35 deletions config/ssmtp/ssmtp.conf.template

This file was deleted.

11 changes: 9 additions & 2 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -21,8 +21,6 @@ services:
- ./logs/wordpress:/var/log/wordpress
# PHP ini config
- ./config/php:/usr/local/etc/php
# SSMTP config
- ./config/ssmtp:/etc/ssmtp/templates:ro
# Share shell scripts
- ./sh:/shell:ro

@@ -58,6 +56,15 @@ services:
PMA_PASSWORD: ${MYSQL_ROOT_PASSWORD}
UPLOAD_LIMIT: 500M

mailhog:
image: "${APP_MAILHOG_IMAGE}"
container_name: "${APP_NAME}_mailhog"
restart: no
ports:
- "8025:8025"
- "1025:1025"

networks:
project_network:
driver: bridge
external: true
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -36,8 +36,6 @@ services:
- ./logs/wordpress:/var/log/wordpress
# PHP ini config
- ./config/php:/usr/local/etc/php
# SSMTP config
- ./config/ssmtp:/etc/ssmtp/templates:ro
# Share shell scripts
- ./sh:/shell:ro

2 changes: 0 additions & 2 deletions dockerfiles/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ RUN set -eux; \
ghostscript \
# Alpine package for "imagemagick" contains ~120 .so files, see: https://github.com/docker-library/wordpress/pull/497
imagemagick \
# Use SMTP relay service
ssmtp \
# Envsubst for operate with env variables in config files
gettext \
# Install wp-cli dependencies
39 changes: 0 additions & 39 deletions dockerfiles/php/docker-entrypoint.d/20-prepare-configs.sh

This file was deleted.

17 changes: 3 additions & 14 deletions sh/env/.env.secret.template
Original file line number Diff line number Diff line change
@@ -45,20 +45,9 @@ WP_SECURE_AUTH_SALT='generate_key'
WP_LOGGED_IN_SALT='generate_key'
WP_NONCE_SALT='generate_key'

# sSMTP config
# See an example https://www.wordpressdocker.com/mailgun-ssmtp/
SSMTP_ROOT=postmaster
SSMTP_MAILHUB=mail:25
SSMTP_AUTHUSER=email@email.com
SSMTP_AUTHPASS=yourPassword
SSMTP_USETLS=YES
SSMTP_USESTARTTLS=YES
SSMTP_REWRITEDOMAIN=localhost
SSMTP_HOSTNAME=localhost
SSMTP_FROMLINEOVERRIDE=YES
SSMTP_DEBUG=NO

SSMTP_REVALIASES=root:your_login@your.domain:mailhub.your.domain[:port]
# SMTP config
SMTP_USER=admin@example.com
SMTP_PASS="generate_this_pass"

# wp-login.php Basic Auth protection
APP_BA_USER=control_area
10 changes: 10 additions & 0 deletions web/wp-config/wp-config.php
Original file line number Diff line number Diff line change
@@ -190,6 +190,16 @@ function getenv_docker($env, $default)
*/
define('WP_DEFAULT_THEME', getenv_docker('WP_DEFAULT_THEME', ''));

/**
* Set the SMTP settings
*/
define('SMTP_HOST', getenv_docker('SMTP_HOST', ''));
define('SMTP_PORT', getenv_docker('SMTP_PORT', ''));
define('SMTP_USER', getenv_docker('SMTP_USER', ''));
define('SMTP_PASS', getenv_docker('SMTP_PASS', ''));
define('SMTP_SECURE', getenv_docker('SMTP_SECURE', ''));
define('SMTP_DEBUG', getenv_docker('SMTP_DEBUG', 0));


/* Add any custom values between this line and the "stop editing" line. */

0 comments on commit f47f986

Please sign in to comment.