launchd, launchctl, and postfix on MacOS 11 'Big Sur', 12 'Monterey', and 'Ventura'
or
Introduction to postfix on MacOS
MacOS uses postfix as the default MTA. No postfix configuration changes are necessary to send mail on the default MacOS installation. Although 'sudo postfix status' shows it not running, the default postfix application is initialized and will restart with any 'sendmail' command when needed, run for 60 sec, then stop. Check 'lsof | grep postfix' to see the files which are open. Then check this by sending a message from Terminal:
mail -s "Test message from macbook" recipient@computer.domain.tld
This is a test mail seen with the default Big Sur install.
Cheers,
G
^D
EOT
You (that is if you are recipient logged into computer.domain.tld and the receiving computer has a running STMPD) should get the message by entering mail on your terminal application.
MacOS does this by initializing postfix as a LaunchDaemon under launchd with a plist like so (System/Library/LaunchDaemons/com.apple.postfix.master.plist):
<?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>
<string>-e</string>
<string>60</string>
</array>
<key>QueueDirectories</key>
<array>
<string>/var/spool/postfix/maildrop</string>
</array>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
which instructs launchd to monitor the /var/spool/postfix/maildrop folder and to execute postfix for 60 seconds if there is a change in the watched folder (caused by an message being written to the folder by mail/sendmail). Thus, postfix is running as what is termed as a 'null client' which allows delivery of mail from cron or other applications. It can also send mail out to the network.
However, to receive mail, an SMTP server must be running and listening on the appropriate port. For MacOS, postfix is the default but you could install another like OpenSMTPD - which is easier to configure and setup than postfix. OTOH, using the base MacOS components is fairly easy as well. You need only to edit the configuration of postfix (which is tricky as it is in the SIP on MacOS 11 and 12 and in an unalterable volume on MacOS 13. Plus, you risk breakig the functionality which handles system messages. In Part 2, I describe a way to do this which is depecated andnot recommended. In Pat 3, I decscribe a much simpler and safe way to do this, tested for MacOS 11 and higher.
Posted by Gordon, No Hair Github Pages, April 12, 2020; revised April 20, 2022.
© nohair.net and the author
For comments, corrections, and addenda, email: gordon[AT]baskin.network