I had a situation where I wanted to send SMTP from inside a Docker container, so I gave it a try using mailhog.
I based this almost entirely on the article above (in Japanese)
What I changed
- Changed the Dockerfile image to
almalinux
Because centos8 is past EOL and an error came up when fetching packages - Added
privileged: trueto docker-compose.yml
It did start with cap-add as well, but errors were being emitted
Send test
- Once it has finished starting up, check inside the Docker container whether postfix can send on port 25.
- Since relayhost uses mailhog’s port 1025, it is not actually sent to the real destination, so there is nothing to worry about
- On the host side you can send on port 1025 as is
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 0d95f56f386c.example.com ESMTP Postfix
mail from: <[email protected]>
250 2.1.0 Ok
rcpt to: <[email protected]>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject: mail testing
it is testing
.
250 2.0.0 Ok: queued as 367DF26008ALeave the Docker container, access http://localhost:8025 in a browser on the host side, and if the mail has arrived you are done