Setting Up Postfix to Work with MAMP

When developing Drupal websites locally, you may want to be able to send emails for testing purposes and have them all get rerouted to you for debugging purposes. At Duo, I’m often working on database dumps from production sites that have many user accounts and I want to make sure that when sending these test emails, none of the actual users receive the test emails.

Gmail Inbox

We use MAMP and I wanted to set it up so that the emails from Drupal would be sent through our Gmail email address but I had some trouble getting Postfix to work in MAMP. I tried many different configurations, but I found that the Postfix settings tab in MAMP did not result in a working configuration. Whenever I run into a challenge like this I start by asking my team if they already have a solution. In this case, I ended up coming up with a solution. The instructions below detail the steps I took to set up Postfix to work with MAMP and includes settings that re-route all emails sent to a single email address for testing.

CTA 1 - Don't Wait to MIGR8

Don’t Wait to MIGR8

Let Duo guide you on the right path to Drupal 8.

How to Set Up Postfix to Work With MAMP

These instructions are for a OS X Mavricks enviroment running MAMP

Start by opening Terminal and enter the following command:
open /var/log/mail.log

This opens up mail log in the console to monitor for errors. Open the file /etc/postfix/ in VIM or any text editor.

Add the following lines to end of file:

myorigin =
myhostname =
relayhost = []:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
inet_protocols = ipv4
smtp_use_tls = yes
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical

Edit file /private/etc/postfix/ and uncomment the line beginning with "tlsmgr" (remove sharp).

Create a sasl_passwd File to Authenticate with Google's Servers

Next we need to create a sasl_passwd file that will be used to authenticate with google’s servers.

From the command line create and edit the file:
sudo nano /etc/postfix/sasl_passwd

Add the following line to the file contents replacing with your gmail username:

Depending on your Google security settings, you probably will require an app specific password to use instead of your normal Gmail password. After editing these files, we need to secure the password file and tell Postfix to update all the configurations.

Run these commands from the command line:

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

To check this is working, try sending a test email.
date | mail -s test

Setting Up Postfix So All Emails Get Sent to One Email Address

At this point you can send emails to any gmail account, but we can take it one step further and set up postfix so that all emails it sends get sent to one email address. This is useful for testing on the local environment so that test emails are not sent out to real users.

Create file /etc/postfix/sender_canonical

Create file /etc/postfix/recipient_canonical

Run some more commands.

sudo postmap /etc/postfix/recipient_canonical
sudo postmap /etc/postfix/sender_canonical
sudo postfix upgrade-configuration

Reload postfix again.

sudo postfix reload
sudo postfix flush

Now all emails sent by postfix will be sent to the address you entered in /etc/postfix/recipient_canonical and will be sent from the address entered in /etc/postfix/sender_canonical

Try another test email.
date | mail -s test

No matter what email address we give, the email should get sent to the address in /etc/postfix/sender_canonical

Caution: MAMP will overwrite the changes to and if you click the "use this data" button on the Postfix tab.

By following these directions you will be able to have all test emails rerouted to you when working in MAMP. 

CTA 4 - Got a Project? - Let's Talk!

We Like Challenges.

Our team of experts can help your organization
reach its digital goals.

This post was updated with new information on June 21, 2016.