at posts/single.html

fetchmail でISPのメールを取得

ようやくPostfixが動作したので、fetchmailを使ってISPのメールを取得できるようになった。

fetchmailのインストールは、# emerge fetchmail でOK。ホームディレクトリに .fetchmailrc というファイルを作成し、ISPのメールサーバなどの設定を書き込む。記述方法はFetchMailの導入を参考にした。

set postmaster machu
set nobouncemail

defaults
protocol pop3
keep
no mimedecode
smtphost localhost

poll <POPサーバのアドレス>
  user <ユーザID> pass <パスワード>

.fetchmailrc のパーミッションを710とし、fetchmailを実行すると指定したサーバからメールを取ってきてくれる。

$ fetchmail
27 messages for kohei@machu.jp at s40.xrea.com (67701 octets).
reading message kohei@machu.jp@s40.xrea.com:1 of 27 (1600 octets) . not flushed
reading message kohei@machu.jp@s40.xrea.com:2 of 27 (2663 octets) .. not flushed
reading message kohei@machu.jp@s40.xrea.com:3 of 27 (3275 octets) ... not flushed

 (中略)

reading message kohei@machu.jp@s40.xrea.com:26 of 27 (995 octets)  not flushed
reading message kohei@machu.jp@s40.xrea.com:27 of 27 (1026 octets) . not flushed

取得したメールは、Postfixを経由してホームディレクトリの .maildir/new/ に格納される*1。 ちなみに、Postfixがちゃんとメールを処理したかどうかは、 /var/log/mail.log で確認できる*2

しかし、今のままだとメールサーバにメールが残ったままになるので、 fetchmailを実行するたびに同じメールがmaildirに追加されてしまう・・・。環境構築が終わったら、fetchmailrcからkeepの指定を除こう。

次はいよいよIMAPサーバ (bincimap) に挑戦だ。

関連する日記