ターミナルからメールを送信する

http://kawama.jp/archives/2011/05/linux_mail_oneliner.html

echo "mail body" | mail -s "mail subject" hoge@example.com

mountain lionで試したらエラーが出た。

sendmail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory

次のコマンドを実行。
http://blog.sarabande.jp/post/29081891413

sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start

これを使うと、あるコマンドが正常終了or異常終了したらメールを送る、ということが可能になる。

command && mail -s "success" foo@example.co.jp
⇒ command が成功したらコマンド成功通知メールを送信する。
command || mail -s "error" foo@example.co.jp
⇒ command が失敗したらエラー通知メールを送信する。