
Mac OS X Lionでmailコマンドを使ってメールを送信する方法です。
例では、GmailのSMTPサーバを中継してメールを送信しています。
環境
Mac OS X Lion 10.7.3
Postfix 2.8.4
Postfix 2.8.4
GmailのSMTPサーバのアドレスと、認証で使用するユーザ名、パスワードを記述したファイルを/etc/postfix/relay_passwordとして作成します。(ファイル名は任意で構いません)
/etc/postfix/relay_passwd
smtp.gmail.com:587 foo@gmail.com:password
postmapコマンドで上記ファイルから検索データベースを作成します。
$ sudo postmap /etc/postfix/relay_passwd
/etc/postfix/relay_password.dbが作成されたのを確認したら、/etc/postfix/relay_passwdを削除します。(パスワードを平文で記述しているため)
$ sudo rm -rf /etc/postfix/relay_passwd
/etc/postfix/main.cfに下記の設定を追加します。
# メールを中継するホスト relayhost = smtp.gmail.com:587 # SASL認証の設定 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/relay_passwd smtp_sasl_security_options = noanonymous # TLSの設定 smtp_use_tls = yes smtp_tls_security_level = encrypt tls_random_source = dev:/dev/urandom
設定をリロードします。
$ sudo postfix reload
ターミナルからmailコマンドを実行してメールを送信してみましょう。
$ mail -s 'テスト送信のタイトルです' hoge@example.com ←Enter Macからあなたへ ←本文を入力してEnter . ←.(ピリオド)を入力してEnter EOT
これで、hoge@example.comにメールが送信されているはずです。