run mailhog docker and test sending email on MacOS
# run mailhog docker
- Start mailhog directly by docker file
download Dockerfile from mailhog github
build it
docker build -t mailhog .
then run docker with docker run -p 8025:8025 -p 1025:1025
above command means run docker image and mount port 8025 to 8025 on docker, and port 1025 on your machine to port 1025 on docker
- Run immediately by one command
docker run -p 8025:8025 -p 1025:1025 mailhog/mailhog
above command will build and run docker for you
- Via docker composer
create docker-composer.yml file with below content
version: "3"
services:
mailhog:
image: mailhog/mailhog:latest
restart: always
ports:
- 1025:1025
- 8025:8025
run it: docker-composer up -d mailhog
now you can access mailhog client by: http://localhost:8025
# Config postfix and send sample email on MacOS
- Config postfix
sudo vi /etc/postfix/main.cf
add these two lines to postfix config file
myhostname = localhost
relayhost = [127.0.0.1]:1025
stop and start postfix: sudo postfix stop && sudo postfix start
- send sample email
date | mail -s "Hello — subject here" test@any.com
now you can observe email from http://localhost:8025