MacOS Sierra High comes with preinstalled postfix. Follow these steps to configure it on a local system:
sudo nano /etc/postfix/sasl_passwd- Add this to the file
smtp.gmail.com:587 [email protected]:PASSWORDReplace EMAIL with your gmail username and replace PASSWORD with your gmail password.
- Create a lookup table
sudo postmap /etc/postfix/sasl_passwd
- Open postfix's
main.cf
sudo nano /etc/postfix/main.cf- Edit these values if they are not set already
mail_owner = _postfix
setgid_group = _postdrop- Add these fields at the end of the file (I am choosing
mtp.gmail.comas myrelayhostto send email from gmail account. You can choose any other SMTP relayhost)
#Gmail SMTP
relayhost=smtp.gmail.com:587
# 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/urandomIf you are using gmail then you must have to enable less secure app access.
-
Open
/System/Library/LaunchDaemons/com.apple.postfix.master.plist
sudo nano /System/Library/LaunchDaemons/com.apple.postfix.master.plist- Remove these lines
<string>-e</string>
<string>60</string>and add these lines
<key>KeepAlive</key>
<true/>- Reload and relaunch the deamon
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.postfix.master.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.postfix.master.plistTest by sending a mail
echo "Postfix setting test" | mail -s "Hello Postfix" "[email protected]"Replace [email protected] with the email id of recipent.
mailq: Check mails in the queue and errors if mail not sent.sudo postfix flush: Flush the queue.sudo postsuper -d ALLDelete mails in the queue.sudo rm /var/mail/$USERRemove all mails from local host.sudo postfix startStart postfix mail system.sudo postfix stopStop postfix mail system.sudo postfix reloadReload postfix mail system.