- Source: http://www.developerfiles.com/how-to-send-emails-from-localhost-mac-os-x-el-capitan/
- Source: http://budiirawan.com/install-mail-server-mac-osx/
- Source: https://apple.stackexchange.com/questions/32228/whats-the-correctly-way-to-make-postfix-run-permanently-on-lion-not-server
sudo vi /etc/postfix/main.cf- Ensure that the following values are set:
mail_owner = _postfix setgid_group = _postdrop - Add the following lines at the end of the file:
# Postfix as relay # #Gmail SMTP relayhost=smtp.gmail.com:587 #Hotmail SMTP #relayhost=smtp.live.com:587 #Yahoo SMTP #relayhost=smtp.mail.yahoo.com:465 # Enable SASL authentication in the Postfix SMTP client. smtp_sasl_auth_enable=yes smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd smtp_sasl_security_options=noanonymous smtp_sasl_mechanism_filter=plain # Enable Transport Layer Security (TLS), i.e. SSL. smtp_use_tls=yes smtp_tls_security_level=encrypt tls_random_source=dev:/dev/urandom
sudo sh -c 'echo "\nsmtp.gmail.com:587 [email protected]:your_password" >> /etc/postfix/sasl_passwd'Replace [email protected] and your_password with actual values.sudo postmap /etc/postfix/sasl_passwd
-
Copy the postfix master plist out of System folder.
sudo cp /System/Library/LaunchDaemons/com.apple.postfix.master.plist /Library/LaunchDaemons/org.postfix.custom.plist -
sudo vi /Library/LaunchDaemons/org.postfix.custom.plist -
Change the label value from
com.apple.postfix.mastertoorg.postfix.customRemove these lines to prevent exiting after 60s
<string>-e</string> <string>60</string>Add these lines before
</dict><key>KeepAlive</key> <true/> <key>RunAtLoad</key> <true/> -
Relaunch the daemon.
sudo launchctl unload /Library/LaunchDaemons/org.postfix.custom.plist sudo launchctl load /Library/LaunchDaemons/org.postfix.custom.plist -
Check that daemon has started.
sudo launchctl list | grep org.postfix
In Gmail we must switch on the option "Access for less secure apps", otherwise we will get the error:
SASL authentication failed
-
echo "Test sending email from Postfix" | mail -s "Test Postfix" [email protected]Change
[email protected]with valid email with mailbox access for easy checking. -
Check mail queue and possible delivery errors with
mailq. -
Check mail log with
tail -f /var/log/mail.log.
Configure postfix as relay for macOS Monterey
I recently had to repeat this process on a brand-new M1 Macbook running MacOS 12.5 (Monterey).
Here is a rewrite of the full instructions, merging my tips from August and September 2020, but
muttinstead ofmailfor sending mail, because I have not attempted mail again.1. Edit postfix configuration file
sudo vi /etc/postfix/main.cfAdd the following lines at the end of the file:
2. Configure
muttI could not find a way to convince
mail(ormailxorMail, which on MacOS are all the same tool) to set the From address, so I used mutt - which I installed with Homebrew (brew install mutt). I configured mutt by creating file~/.muttrcwith the following content (with appropriate modifications to use your own name and email address):3a. for iCloud users:
For reference, see helpful information from this Apple support page.
I also needed to generate an app-specific password here.
3b. for Gmail users: Turn on less secure apps (unverified)
In Gmail we must switch on the option "Access for less secure apps", otherwise we will get the error:
SASL authentication failed(I have not verified this information is up-to-date in 2022)
4. Create sasl_passwd file
sudo vi /etc/postfix/sasl_passwdCreate this file with one of these lines, corresponding to your email provider:
smtp.mail.me.com:587 [email protected]:your_passwordsmtp.gmail.com:587 [email protected]:your_passwordsmtp.live.com:587 [email protected]:your_passwordsmtp.mail.yahoo.com:465 [email protected]:your_passwordReplace
your_emailandyour_passwordwith actual values.sudo postmap /etc/postfix/sasl_passwdto inform postfix of the creation or modification of the passwd file.
sudo chmod 640 /etc/postfix/sasl_passwd*to prevent others from reading your password files.
5. Autorun postfix on boot and restart postfix
I found this step (creating
org.postfix.custom) to be unnecessary.I was able to send mail (with
mutt) via postfix, either from the command-line or from scripts.Indeed, I launch some scripts with personal
launchctlplists, and they can send mail too.6. Test
echo "Test sending email from Postfix" | mutt -s "Test Postfix" [email protected]Change
[email protected]with valid email with mailbox access for easy checking.Check mail queue and possible delivery errors with
mailq.a. If you fill your mail queue with failed messages,
sudo postsuper -d ALL deferred