Skip to content

Instantly share code, notes, and snippets.

@ryanjohnston
Last active September 10, 2018 14:17
Show Gist options
  • Save ryanjohnston/3b5b5e887b926641f47317edf7ac03db to your computer and use it in GitHub Desktop.
Save ryanjohnston/3b5b5e887b926641f47317edf7ac03db to your computer and use it in GitHub Desktop.
[๐Ÿ›  MacOS - Postfix] Configuration and setup #config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.postfix.master</string>
<key>Program</key>
<string>/usr/libexec/postfix/master</string>
<key>ProgramArguments</key>
<array>
<string>master</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>QueueDirectories</key>
<array>
<string>/var/spool/postfix/maildrop</string>
</array>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
#!/usr/bin/env bash
#
# sudo cp com.apple.postfix.custom.plist /Library/LaunchDaemons/com.apple.postfix.custom.plist
#
# sudo launchctl unload /System/Library/LaunchDaemons/com.apple.postfix.master.plist
#
# sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist
#!/usr/bin/env bash
# Map user/pass
sudo postmap /etc/postfix/sasl_passwd
# Download thawte root certificate
sudo curl https://www.thawte.com/roots/thawte_Primary_Root_CA.pem -o /etc/ssl/certs/thawte_Primary_Root_CA.pem
cat /etc/ssl/certs/thawte_Primary_Root_CA.pem | sudo tee -a /etc/postfix/cacert.pem

Setup Postfix on MacOS High Sierra

Create an app password and copy password for next step.

Create a file to store our credentials:

$ sudo vim /etc/postfix/sasl_passwd

Add something like this:

smtp.gmail.com:587 username@gmail.com:password

Run setup-postfix.sh from this gist.

$ ./setup-postfix.sh

Open the main postfix config file

$ sudo vi /etc/postfix/main.cf

Add the following at the end of the file. Save when finished.

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
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_always_send_ehlo = yes
smtp_sasl_mechanism_filter = plain

Stop/Start the service

$ sudo postfix stop && sudo postfix start

Check the queue for any errors

$ mailq

Send a test email (replace email@email.com with your email)

$ mail -s 'test' email@email.com < /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment