After years of trying to setup a mail server on macOS without requiring dependencies or messing with ports to trick my ISP into letting mail out, I figured out a solution.
Note: This guide is opinionated towards a Gmail setup.
- Backup the existing Postfix configuration:
sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
- Configure the Postfix mail server:
sudo emacs /etc/postfix/main.cf
# Paste the following under the commented out `relayhost` settings
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_sasl_security_options = noanonymous
smtp_use_tls = yes
# smtp_tls_security_level = encrypt
# tls_random_source = dev:/dev/urandom
- Add Gmail username and password to Postfix:
sudo emacs /etc/postfix/sasl_passwd
# Paste the following into the file
# If using 2FA, you'll need an "app password" here: https://security.google.com/settings/security/apppasswords
smtp.gmail.com:587 EMAIL:PASSWORD
- Generate the hash database and secure the file:
sudo postmap /etc/postfix/sasl_passwd
sudo chown root: /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
- Restart the Postfix mail server:
sudo launchctl stop org.postfix.master
sudo launchctl start org.postfix.master
echo "You are ready to send email from the command-line" | mail -s "Congratulations!" example@gmail.com