Using Homebrew install mailhog
and enable the service as instructed in the installation.
Open in any browser http://localhost:8025
Edit file /etc/postfix/main.cf
sudo vim /etc/postfix/main.cf
and add in the following below the commented out relayhosts :-
myhostname = localhost
.
.
.
# find relayhost section and add:
relayhost = [localhost]:1025
sudo launchctl stop org.postfix.master
sudo launchctl start org.postfix.master
test by sending the contents of a directory to an email address with the following:
tree /var/www/somefolder | mail -s "contents" [email protected]
If you receive the following error:
send-mail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory
you can do the following:
sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start
as per this question.
NB: If things aint sending / receiving, and you're getting notices, check that the mail servers you're using are actually working!
Just to answer @mfernea question above so it doesn't confuse anyone: you don't have to change anything in
php.ini
, the default value PHP uses is/usr/sbin/sendmail -t -i
. After adding the relayhost to Postfix config PHP will continue to use default sendmail, which, in turn, will now properly handle sending emails and MailHog will be able to catch them.Also, confirmed to work just fine on High Sierra.