mail and mailx fail to send emails to gmail
OS X has postfix installed by default but it's not enabled (started). You can start it with

sudo postfix start


you can check the status and eventual problems in /var/log/mail.log

The configuration is in /etc/postfix/