Postfix auto start on Sierra for smtp relay

Postfix works great when I start it manually. Can relay off of it from other hosts on my network; telnet to it on port 25 etc.

How do I get it to auto start such that It will always be listening on port 25?

I understand it starts up every minute or so and sends whatever has been manually written to the queue (like with the mail command) but I want it listening for connections on port 25 (Which it does if I start it manually).

I've found a bunch of things online but can't get any to work (they seem to apply to previous versions of OS X).


To get this working on Sierra you have to modify the existing launch daemon slightly:

  • Disable SIP
  • Modify /System/Library/LaunchDaemons/com.apple.postfix.master.plist:

    sudo nano /System/Library/LaunchDaemons/com.apple.postfix.master.plist
    

    remove the lines:

    <string>-e</string>
    <string>60</string>
    

    add the lines:

    <key>KeepAlive</key>
    <true/>
    

    save the file and exit nano

  • Reload the launch daemon:

    sudo launchctl unload /System/Library/LaunchDaemons/com.apple.postfix.master.plist
    sudo launchctl load /System/Library/LaunchDaemons/com.apple.postfix.master.plist
    
  • Enable SIP


I'm running macOS Catalina.

I copied com.apple.postfix.master.plist from /System/Library/LaunchDaemons/ to /Library/LaunchDaemons as @Johnson suggested in his answer. I then proceeded to make the changes specified by @klanomath in his answer.

On running sudo launchctl load /Library/LaunchDaemons/com.apple.postfix.master.plist, I got this: service already loaded. I tried unloading the service but SIP would not allow it.

After some more searching, I found https://github.com/alexzhangs/macos-postfix-autostart. This repo is no longer maintained but the author said that postfix service will be started on demand when calling sendmail.

I've tested and confirmed this works. So you really don't have to auto start postfix in newer OS'.


It is not necessary or recommended to modify plists in /System/Library/LaunchDaemons – rather make a copy in /Library/LaunchDaemons and modify that.


I needed a daemon listening on port 25 for local clients, so I still had to do the local LaunchDaemon setup on Catalina. The basic technique in the github scripts still works without having to hack around the protections. Using sudo, copy over the default one to /Library/LaunchDaemons and rename the file and change the Label value inside the file; what you call it doesn't matter. I used the name org.postfix.custom.plist. I removed the 60 second exit params and set RunAtLoad and KeepAlive LaunchDaemon keys to true. That worked for me. I have the following in my /Library/LaunchDaemons/org.postfix.custom.plist file. [This is the whole file.] You must then reboot because Catalina doesn't allow you to unload the existing config yourself.

<?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>org.postfix.custom</string>
        <key>Program</key>
        <string>/usr/libexec/postfix/master</string>
        <key>ProgramArguments</key>
        <array>
                <string>master</string>
        </array>
        <key>QueueDirectories</key>
        <array>
                <string>/var/spool/postfix/maildrop</string>
        </array>
        <key>AbandonProcessGroup</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
</dict>
</plist>