How to set up sending email with Mamp on a Mac Mini

  |   By  |  0 Comments

What a pain in the neck!

I tried Mailhog and just couldn’t it working on my M1 Mac Mini, so I’ve gone down the Postfix route and got it working and diverting all emails to one email address.

You are going to be using the Terminal (which is in Applications > Utilities)

Open that up and type


That should give you the following error, showing it exists

postfix: error: to submit mail, use the Postfix sendmail command
postfix: fatal: the postfix command is reserved for the superuser

I’m using my gmail account as the smtp server, so you will need an app specific password.

In your terminal, type or copy and paste this

sudo vi /etc/postfix/

Then your Mac password.

That will open the file up in the worst looking terminal editor ever. Scroll down and look for

mail_owner = _postfix
setgid_group = _postdrop

You edit by placing the cursor where you want to put it then the i key to go into edit mode.

Next scroll to the bottom and copy and paste this code to set up gmail as the smtp server

# Use Gmail SMTP
relayhost =
smtp_sasl_mechanism_filter = plain
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandom

Now you can save the file – Click on the ESC key and then type :wq – w is for save and q is for quit.

Now we need to create a gmail username/password file with you app specific password.

sudo vim /etc/postfix/smtp_sasl_passwd

Press i to start inserting and add the following

Click ESC key and then :wq to save and exit.

This command will tell postfix to look at that file

sudo postmap /etc/postfix/smtp_sasl_passwd

Now we need to set it up for TLS

sudo vim /etc/postfix/smtp_tls_sites

Click i to insert and add


Then click ESC key followed by :wq to save and exit

We tell postfix to understand that with

sudo postmap /etc/postfix/smtp_tls_sites

Final step to get Postfix working is

sudo postfix start

You’ll want this to start every time you start up your Mac, so type this…

sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist

That stops that file

Then you can edit it with

sudo vim /System/Library/LaunchDaemons/org.postfix.master.plist

Remove these lines.


and add


Then you can restart that file

sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist

Check it works with

echo "Test sending email from Postfix" | mail -s "Test Postfix"

How to divert all outgoing emails to one email address

In the terminal…

sudo vim /etc/postfix/main.c

Click i to insert and add

canonical_maps = regexp:/etc/postfix/canonical-redirect

Click ESC then :wq to save and exit

Now we are going to create a file with the divert to email address

sudo sh -c 'echo "\n/^.*$/" >>/etc/postfix/canonical-redirect'

Then this will create the file needed by postfix

sudo postmap /etc/postfix/canonical-redirect

Try this, just in case it is needed

sudo postfix reload

Give yourself a little test-email.php script to make sure it works

if(mail('',"Test email Title","Lorum ipsum is the email body")) echo "Mail sent";

That should go to

You’re welcome.