- 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.master
toorg.postfix.custom
Remove 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
.
Thank you, this was very helpful. It worked for me on Catalina for sending mail via iCloud (because I have/want no gmail).
Some recommendations to update the documentation:
sudo vi /etc/postfix/sasl_passwd
to edit the file after it is created. This approach also avoids dropping your cleartext password into your bash history, which is poor practice./var/log/mail.log
, at least on Catalina; I think one must look in the Console for syslog messages from postfix.sudo postsuper -d ALL deferred
mail
to send a test message may not work; I found it labeled my outbound mail as being 'from' address[email protected]
, drawing from the MacOS username and the hostname of my laptop. Such messages appear to leave my machine but are never delivered. I could not find a way to convincemail
(ormailx
orMail
, which on MacOS are all the same tool) to set the From address, so I usedmutt
and set the 'from' and 'envelope' in.muttrc
as follows:Recommendations for iCloud users:
In step 1, use the following and comment out Gmail:
For reference, see helpful information from this Apple support page.
I think I needed to generate an app-specific password here.
I'm not sure this was necessary, but I strongly recommend it because it avoids placing your normal iCloud password, in cleartext, in the
/etc/postfix/sasl_passwd
file. In the event that password is compromised, or laptop lost, I assume it is possible to revoke that app-specific password from an interface on apple.com.