Send mails from command line on Mac OS X 10.10 Yosemite

Edit mail.cf

Add following line on /etc/postfix/main.cf. $ sudo vim /etc/postfix/main.cf

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
smtp_sasl_mechanism_filter = plain # only for yosemite

Add password config file

Add following line on /etc/postfix/sasl_passwd. $ sudo vim /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 username@gmail.com:password

Reflect config change

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

Test

$ date | mail -s "testing" email@adderess.to