If you’re anything like me, you love to work locally building websites without relying on a live server, but this can present some drawbacks such as limiting the full functionality of your site, specifically, the ability to test outgoing emails. In this post I will show you how to take your development even further and without bounds by enabling the ability to send emails from local with Postfix.
I use MAMP Pro which comes packaged with postfix, however I needed some additional tweaks to get it going smoothly. I tried many different ways to make postfix work out of the box with MAMP, but alas I was unsuccessful. A major bummer, because has a “lazy developer” I like the easy straightforward approach as much as the next dev.
Step 1. Setting up a working Postfix MAMP configuration
These instructions are working for me on OS High Sierra with MAMP version 4.4.1
Open the terminal and enter the following command
This will open the mail log console where you can follow along for warnings and errors.
Open the file /etc/postfix/main.cf in your favorite editor
- Add the following lines at the bottom of the file.
relayhost = [smtp.gmail.com]:587
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_mechanism_filter = plain
inet_protocols = ipv4
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandom
Step 2. Create then edit the sasl_passwd file to allow authentication with your Google Account
Enter this command in terminal:
$sudo vi /etc/postfix/sasl_passwd
Add the following lines
Step 3. Enter the following commands to restart postfix
$sudo chmod 600 /etc/postfix/sasl_passwd
$sudo postmap /etc/postfix/sasl_passwd
$sudo launchctl stop org.postfix.master
$sudo launchctl start org.postfix.master
$sudo postfix upgrade-configuration
Next, reload Postfix.
$sudo postfix reload
$sudo postfix flush
Test that the configuration is working
$date | mail -s testing email@example.com