This document is based on Anuj Gakhar’s post On December 9, 2011 in http://www.anujgakhar.com/2011/12/09/using-macosx-lion-command-line-mail-with-gmail-as-smtp/
I have been looking for a way to setup a command line mail (or mailx) working on OSX 10.10 (Yosemite) and I found a good blog posting by Anuj Gakhar for OSX Lion. I elaborated a little bit more by Google search and found a quick fix for OSX Yosemite in http://stackoverflow.com/questions/26447316/mac-os-x-10-10-yosemite-postfix-sasl-authentication-failed. I have added new information for OSX Yosemite.
This method is especially useful when you do not setup mail host on your Mac.
Here are the steps I followed.
Configure Postfix for SMTP.
- Edit file /etc/postfix/main.cf
>> sudo vim /etc/postfix/main.cf
- Add in the following below the commented out relayhosts. relayhost can be any SMTP mail service such as [smtp.gmail.com]:587, [smtp.live.com]:587, etc.
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
- Add below line at the bottom if you are using OSX 10.10 Yosemite
smtp_sasl_mechanism_filter = plain
Generate sasl_password if not already exists
>> sudo vi /etc/postfix/sasl_passwd
- Enter in the following (gmail or other SMTP setup used in 1.a. relayhost):
Run the following commands
>> sudo chmod 600 /etc/postfix/sasl_passwd
>> sudo postmap /etc/postfix/sasl_passwd
>> sudo launchctl stop org.postfix.master
>> sudo launchctl start org.postfix.master
All set! Let’s test.
Now, you should be able to send emails from within the command line.
>> date | mailx -s “date test” email@address.to
email@address.to should have received an email from yourusername@gmail.com with subject "date test".