Skip to content

Instantly share code, notes, and snippets.

@madalinignisca
Forked from larrybotha/readme.markdown
Last active August 24, 2022 06:10
Show Gist options
  • Save madalinignisca/55e3cbe1cbd9d3af2daea48b045eeb89 to your computer and use it in GitHub Desktop.
Save madalinignisca/55e3cbe1cbd9d3af2daea48b045eeb89 to your computer and use it in GitHub Desktop.
Postfix Using Mailhog to capture email for web development

Configure Postfix for Localhost SMTP in Mac OSX Mavericks with Mailhog

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

Run the following commands

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!

@mfernea
Copy link

mfernea commented Aug 17, 2017

Hi Madalin! Since this is meant for web development, can you please also share the sendmail_path that you are using in your php configuration?

@ihorvorotnov
Copy link

ihorvorotnov commented Feb 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment