As I'm constantly trying different email applications on my Mac, I wanted a single local SMTP server so I don't have to store my Gmail credentials in each app. Postfix handles the delivery and relays outbound mail through Gmail.

Installation

Nothing to install — Postfix ships with macOS.

Gmail App Password (required since 2022)

Google removed Basic Authentication ("less secure apps") in May 2022. Your regular Gmail password will be rejected by Gmail's SMTP server. You need an App Password instead:

  1. Enable 2-Step Verification on your Google account at myaccount.google.com/security
  2. Go to myaccount.google.com/apppasswords
  3. Create a new App Password — you will get a 16-character code
  4. Use that code in place of your regular password in the step below

If you use Google Workspace (formerly Google Apps), the same applies — generate the App Password from your Workspace account.

Configuration

Create the credentials file:

sudo vim /etc/postfix/sasl_passwd

Add this line, replacing YOUR_APP_PASSWORD with the 16-character code from the step above:

smtp.gmail.com:587 [email protected]:YOUR_APP_PASSWORD

Hash the file so Postfix can read it:

sudo postmap /etc/postfix/sasl_passwd

Edit the main Postfix configuration file:

sudo vim /etc/postfix/main.cf

Add these lines, checking they are not already present:

mydomain_fallback = localhost
mail_owner = postfix
setgid_group = postdrop
relayhost=smtp.gmail.com:587
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

Start the service

sudo postfix start

Configure your email client

Point your email client to localhost port 25. Postfix will handle the relay to Gmail transparently.


Last edit on: March 16, 2012

Last updated on: July 3, 2026

By: Guillermo Garron