fetchmail の導入


  1. fetchmail

    ローカル環境で sendmail が動作するようになりましたのでメールの送信が出来るようになりましたが、受信に関しては依然、外部のサーバを利用することになります。そこで fetchmail を導入することによって外部のサーバのメールをローカルのサーバに取り込むようにしてみます。

  2. ソースのダウンロードと展開

    ソースを入手します。
    例えば SunSite 等からダウンロード可能です。最新のものは Fetchmail Home Page で。

    さくっと展開します。

    tachi@galley 203 % pwd
    /opt/src
    tachi@galley 204 % gzip -cd fetchmail-5.8.0.tar.gz | tar xvf -
    :
    :
    :
    tachi@galley 205 %

  3. SFWflex のインストール

    コンパイル時に必要になりますので GNU flex をインストールします。
    ここでは SOFTWARE Companion CD に収録されているものを pkgadd する場合の例を示します (/opt/sfw/bin にインストールされますので path を通しておきます)。

    # pwd
    /export/sol/s8u4/s8u4x_ccd/components/i386/Packages
    # pkgadd -d . SFWflex
    :
    :
    :
    #

  4. コンパイルとインストール

    展開したディレクトリ下で configure を実行します。

    tachi@galley 208 % pwd
    /opt/src/fetchmail-5.8.0
    tachi@galley 209 % ./configure --prefix=/opt/local
    :
    :
    :
    tachi@galley 210 %

    flex を使用するように Makefile を編集します (v5.8.0 では default で設定されていますので確認だけします)。

    LEX = flex

    make します (/usr/ccs/bin/make ではなく、gmake を使います)。

    tachi@galley 210 % pwd
    /opt/src/fetchmail-5.8.0
    tachi@galley 211 % gmake
    :
    :
    :
    tachi@galley 212 %

    super-user でインストールします。

    # pwd
    /opt/src/fetchmail-5.8.0
    # gmake install
    Creating installation directories...
    /bin/sh ./mkinstalldirs /opt/local/bin /opt/local/man/man1
    Installing fetchmail binary...
    ./install-sh -c ./fetchmail /opt/local/bin/fetchmail
    gmake: execvp: ./install-sh: Permission denied
    gmake: *** [install] Error 127
    # ls -l install-sh
    -rw------- 1 tachi staff 5598 3月 29日 07:51 install-sh
    # chmod a+x install-sh
    # gmake install
    :
    :
    :
    #

  5. .fetchmailrc の作成

    fetchmail を実行するユーザのホームディレクトリに .fetchmailrc ファイルを作成します。例を示します。

    poll pop.hogeracchi.ne.jp
    protocol POP3
    user namae-dayo
    pass "himitsu-dayo"

    no mimedecode

    .fetchmailrc にはパスワードを直接記入しますのでパーミッションを変更します。

    tachi@galley 226 % pwd
    /home/tachi
    tachi@galley 227 % chmod 600 .fetchmailrc
    tachi@galley 228 %

  6. fetchmail の実行

    実行には fetchmail を直接実行します。

    tachi@galley 18 % fetchmail
    fetchmail: No mail for namae-dayo at pop.hogeracchi.ne.jp
    tachi@galley 19 %

    ↓daemon として実行させる場合。

    tachi@galley 49 % fetchmail --daemon 180
    tachi@galley 50 %

  7. 自動起動とか

    パートタイムでインターネットに接続する場合は cron で実行させるのがよさそうです。
    常時接続環境ではOS起動時に自動起動させて daemon として実行します。
    以下は /etc/init.d/fetchmail スクリプトを作成して /etc/rc3.d/S99fetchmail, /etc/rc1.d/K20fetchmail, /etc/rc0.d/K20fetchmail にシンボリックリンクした例です。

    #!/sbin/sh
    #
    # fetchmail
    
    case "$1" in
    'start')
            for user in `ls /export/home/`
            do
                    if [ -f /home/$user/.fetchmailrc ]; then
                            echo "fetchmail for $user starting."
                            su $user -c "/usr/local/bin/fetchmail --daemon 180"
                    fi
            done
            ;;
    
    'stop')
            for user in `ls /export/home/`
            do
                    if [ -f /home/$user/.fetchmailrc ]; then
                            su $user -c "/usr/local/bin/fetchmail --quit"
                    fi
            done
            ;;
    
    *)
            echo "Usage: $0 { start | stop }"
            exit 1
            ;;
    
    esac
    exit 0

    ↓シンボリックリンク。

    # ls -l /etc/init.d/fetchmail
    -rwxr--r-- 1 root other 470 Jul 15 11:48 /etc/init.d/fetchmail
    #
    # ln -s /etc/init.d/fetchmail /etc/rc3.d/S99fetchmail
    # ln -s /etc/init.d/fetchmail /etc/rc1.d/K20fetchmail
    # ln -s /etc/init.d/fetchmail /etc/rc0.d/K20fetchmail
    #

もどる Last modified: 04/09/01 00:40:53