Setting up mail on MAMP on El Capitan

I’ve only recently switched over to Macs and have found setting up mail sending on the MAc’s MAMP as hard as Windows! So here’s how.

Firstly it all needs to be down in the “Terminal” – so click on Finder, then Applications, then Utilities to open a terminal (looks pretty similar to Windows CMD!)

Check a program called Postfix exists by typing

Postfix

That should give you the following errors – which for once is good news!
postfix: error: to submit mail, use the Postfix sendmail command
postfix: fatal: the postfix command is reserved for the superuser

Next we can start configuring for gmail – but first head over to you gmail account to set up using for less secure apps

In the terminal type or copy and paste
sudo vi /etc/postfix/main.cf

Than type your password and enter.
Scroll down and check the following lines exist…

mail_owner = _postfix
setgid_group = _postdrop

Editing took some googling for me as it is not intuitive! Here’s a cheatsheet
i) To delete – put the cursor over the character and press x
ii) To start inserting – place your cursor and press i, then start type or use copy (CTRL C) and paste (CTRL V).
To exit with out saving press key and then :q
To exit with saving press and then :wq

At the bottom of the file add the following

# Use Gmail SMTP
relayhost = smtp.gmail.com:587
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

You can change the relayhost to whatever server you like, I’m using gmail.
We need to create a gmail username/password file. So save and exit the main.cf file – , followed by :wq

Type
sudo vim /etc/postfix/smtp_sasl_passwd

and press i to start inserting again and add the following line

smtp.gmail.com:587 your_username@gmail.com:your_password

Save the file using :wq
Now we need to get it turned into what postfix wants by typing

sudo postmap /etc/postfix/smtp_sasl_passwd

Next we need to set it up for TLS

sudo vim /etc/postfix/smtp_tls_sites
Press i to start editing and add

[smtp_gmail.com]:587 MUST_NOPEERMATCH

Save :wq

And then type

sudo postmap /etc/postfix/smtp_tls_sites

And then sudo postfix start

Now we just need to test it all!
echo "Test sending email from Postfix" | mail -s "Test Postfix" youremail@domain.com

A quick php script to test from your MAMP server



Lastly to make these changes work for starting up your mac we need to do some more worrk, changing a file called /System/Library/LaunchDaemons/org.postfix.master.plist
which is read only because it is being used!

sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist stops it!
Add the following before
RunAtLoad
KeepAlive

And then restart the daemon thingie…
sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist

Hope that helps you!