Tag: postfix



2011 6月30日

DNSの逆引き設定

今まで逆引き設定していなかったメールサーバから送ったメールには

Received: from sv.domain.com (sv.domain.com [127.0.0.1])
	by mail.domain.com (Postfix) with SMTP id…

のようなヘッダとなっていて、localhost(127.0.0.1)から送られたものだとされていた。

これが迷惑メールとされる一因なので、mail.domain.com はちゃんとしたサーバですよー、と知らせるためにグローバルなIPアドレスをあててあげる。

DNSの逆引きはドメインの管理とは関係ないので、回線業者が提供するサイトなりツールから設定。メールサーバのドメインが mail.domain.com、IPアドレスが111.222.33.4 の場合。
111.222.33.4にmail.domain.comを割り当てる。

逆引きを設定すると

Received: from 111.222.33.4  (EHLO maildomain.com) (111.222.33.4)
  by mta...

のようなヘッダとなる。

Gmailではこれだけで迷惑メールと判断されなくなった。

Yahooメールでの対策

上記対応をして一時的に改善しても、1日程度経つと再び迷惑メールに振り分けられる場合がある。この場合はメールヘッダに X-YahooFilteredBulk: 111.222.33.4 等と入っている可能性があるので、Yahooに問い合わせる必要がある。

オープンリレーを許可していないか確認する。

第三者中継チェック RBL.JP

全てが青い文字で no relays accepted. となればおk.

Yahooに問い合わせ

Yahoo!メール(ベータ版) ヘルプ – [迷惑メール]フォルダに振り分けられたくないメールがある
へ行き、一番下の「解決しましたか?」でいいえを選択すると問い合わせフォームになるのでそこから問い合わせる。

きちんとすれば、予想以上に早い対応をしてもらえる。
対応後にはこんなメールを頂ける。

◯◯◯◯ ◯◯様

Yahoo!メールカスタマーサービス◯◯です。
このたびは、調査および調整に必要な情報をご提供くださいまして、
誠にありがとうございました。

お問い合わせの「Yahoo!メール・迷惑メールフォルダへのメール振り分け」に
ついてご案内いたします。

お知らせいただいた情報をもとに調査を行い、ご利用のメールサーバーに
問題がないことを確認しましたので、弊社にて調整を実施いたしました。
・・・以下(ry

まさに Amazon EC2のサーバからメール送信をするまでにやるべきこと (スパムメール扱いを回避する!) – RX-7乗りの適当な日々

DNS逆引き設定
SPFの設定
SPAMメールのブラックリストに対する解除申請

のまんまですが。

SPFについて

とりあえず逆引き設定で迷惑メールに振り分けられる問題は改善したのだけど、SPF(Sender Policy Framework)を設定しておくともっとよさそう。

SPFは 送信者(from) が taro@domain.com なら domain.com が評価対象となる。メールサーバは関係ないようだ。fromのFQDN部分が使われる様子。

DNSの設定でTXTレコードを設定する。

Yahooでパスしたメールには

Received-SPF: pass (mail.domain.com: domain of info@domain.com designates 27.....

のようなヘッダが追記されていた(当然受信側のメールサーバがSPFに対応していることが前提)

チェックするにはこのようなツールも。

Sendmail – SPFレコードチェック
http://www.sendmail.co.jp/sa/spfcheck.html

参考:

  • Amazon EC2のサーバからメール送信をするまでにやるべきこと (スパムメール扱いを回避する!) – RX-7乗りの適当な日々
  • サービスから送るメールがスパム扱いされないために。
  • メール送信者認証技術 SPF/Sender ID についてお勉強 :: drk7jp
  • Sender ID:送信者側の設定作業 - @IT
  • 間違いから学ぶSPFレコードの正しい書き方 : 迷惑メール対策委員会






  • 2011 1月6日

    設定項目などはほぼコピペ。自分用のメモ。
    記事中の各リンク先の通り設定したのではなかなか実現できないので多少アレンジしています。

    ローカルのUNIXユーザーはMairdir/方式でメールを使いたい。
    バーチャルドメイン複数の運用、かつ、Web GUIでメールアカウントを管理したい。
    スパムメールとウィルスもチェックしたい。

    このような要望のもと、メールサーバを立て直した際に以前書いた記事をまとめてみた。
    さすがに長文になったので続きを読むにした。

    • CentOS5.5 i386とする
    • ローカルのUNIXユーザはMaildir方式でメールを利用する。
      メールボックスは ~/home/user/Mairdir
    • 複数のドメインをバーチャルドメインで扱う。
      メールボックスは /mail/domain.tld/user@domain.tld
    • PostfixをMTAとしてバーチャルドメインでのメールアカウントはMySQLで管理する。
    • Clam AntiVirusでウィルスチェックを行う。
    • SpamAssassinでスパムチェックを行う。このため配送(transport)はprocmailで行う。

    …つづきを読む







    2009 10月15日

    構築環境

    • CentOS5.3
    • Postfix +MySQL
    • Dovecot
    • postfixadmin
    • procmail (spamassassin、Clam AntiVirus でスパムメールとウィルス対策)

    postfixadminを使ってバーチャルドメインでメールサーバを構築するまではうまくいったのだけど、procmailを使うと自動でメールボックスが作成されない。

    もともとメールアカウント削除してもメールボックスが自動で削除されないので付属のシェルスクリプト改で行ってみるテスト。

    postfixadminは /var/www/postfixadmin に設置してあるとし、

    メールは /mail 以下に保存される設定で。
    各ユーザーのメールボックスは /mail/hoge.com/user@hoge.com な感じ。

    メールディレクトリ作成・削除スクリプトは/usr/local/bin/postfixadmin へ保存する。

    メールボックス作成用スクリプト
    /usr/local/bin/postfixadmin/postfixadmin-mailbox-postcreation.sh

    メールボックス削除用スクリプト
    /usr/local/bin/postfixadmin/postfixadmin-mailbox-postdeletion.sh

    ドメイン削除用スクリプト?
    /usr/local/bin/postfixadmin/postfixadmin-domain-postdeletion.sh

    1)メールボックス作成・削除スクリプト準備

    保存用ディレクトリを作成し、postfixadmin/ADDITIONS 内にある、

    postfixadmin-domain-postdeletion.sh
    postfixadmin-mailbox-postcreation.sh
    postfixadmin-mailbox-postdeletion.sh

    を/usr/local/bin/postfixadmin 以下にコピーする。

    # mkdir /usr/local/bin/postfixadmin
    # cp /var/www/postfixadmin/ADDITIONS/postfixadmin-domain-postdeletion.sh /usr/local/bin/postfixadmin
    # cp /var/www/postfixadmin/ADDITIONS/postfixadmin-mailbox-postcreation.sh /usr/local/bin/postfixadmin
    # cp /var/www/postfixadmin/ADDITIONS/postfixadmin-mailbox-postdeletion.sh /usr/local/bin/postfixadmin

    2)削除メールボックスの保存先

    削除したメールボックスは/mail/.deleted-maildirs 以下に保存されるようにする。

    削除したメールボックスを保存するディレクトリ作成

    # mkdir /mail/.deleted-maildirs
    # chmod 771 /mail/.deleted-maildirs
    # chmod 0700 /mail/.deleted-maildirs
    # chown vuser:vuser /mail/.deleted-maildirs

    3)スクリプトの編集

    ユーザーメールボックス作成用スクリプトの編集
    # vi /usr/local/bin/postfixadmin/postfixadmin-mailbox-postcreation.sh
    
    #!/bin/sh
    
    # Example script for adding a Maildir to a Courier-IMAP virtual mail
    # hierarchy.
    
    # The script only looks at argument 3, assuming that it
    # indicates the relative name of a maildir, such as
    # "somedomain.com/peter/".
    
    # This script should be run as the user which owns the maildirs. If
    # the script is actually run by the apache user (e.g. through PHP),
    # then you could use "sudo" to grant apache the rights to run
    # this script as the relevant user.
    # Assume this script has been saved as
    # /usr/local/bin/postfixadmin-mailbox-postcreation.sh and has been
    # made executable. Now, an example /etc/sudoers line:
    # apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postcreation.sh
    # The line states that the apache user may run the script as the
    # user "courier" without providing a password.
    
    # Change this to where you keep your virtual mail users' maildirs.
    #basedir=/var/spool/maildirs ←コメントアウト
    basedir=/mail ←追記
    
    if [ ! -e "$basedir" ]; then
        echo "$0: basedir '$basedir' does not exist; bailing out."
        exit 1
    fi
    
    if [ `echo $3 | fgrep '..'` ]; then
        echo "$0: An argument contained a double-dot sequence; bailing out."
        exit 1
    fi
    
    maildir="${basedir}/$3"
    parent=`dirname "$maildir"`
    if [ ! -d "$parent" ]; then
        if [ -e "$parent" ]; then
            echo "$0: strange - directory '$parent' exists, but is not a directory; bailing out."
            exit 1
        else
            mkdir -p "${parent}"
            if [ $? -ne 0 ]; then
                echo "$0: mkdir -p '$parent' returned non-zero; bailing out."
                exit 1
            fi
        fi
    fi
    
    if [ -e "$maildir" ]; then
        echo "$0: Directory '$maildir' already exists! bailing out"
        exit 1
    fi
    
    #maildirmake "$maildir" ←コメントアウト
    #if [ ! -d "$maildir" ]; then
    #    echo "$0: maildirmake didn't produce a directory; bailing out."
    #    exit 1
    #fi
    
    
    # 以下を追記
    mkdir "$maildir"
    if [ ! -d "$maildir" ]; then
        echo "$0: mkdir didn't produce a directory; bailing out."
        exit 1
    fi
    
    mkdir "${maildir}cur"
    if [ ! -d "${maildir}cur" ]; then
        echo "$0: mkdir didn't produce a directory; bailing out."
        exit 1
    fi
    
    mkdir "${maildir}new"
    if [ ! -d "${maildir}new" ]; then
        echo "$0: mkdir didn't produce a directory; bailing out."
        exit 1
    fi
    
    mkdir "${maildir}tmp"
    if [ ! -d "${maildir}tmp" ]; then
        echo "$0: mkdir didn't produce a directory; bailing out."
        exit 1
    fi
    
    chown -R vuser:vuser "$maildir"
    chmod -R 700 "$maildir"
    
    exit 0
    ユーザーメールボックス削除スクリプトの編集

    ユーザーメールボックスは、/mail/hoge.com/user@hoge.com の形式としています。

    # vi /usr/local/bin/postfixadmin/postfixadmin-mailbox-postdeletion.sh
    
    #!/bin/sh
    
    # Example script for removing a Maildir from a Courier-IMAP virtual mail
    # hierarchy.
    
    # The script looks at arguments 1 and 2, assuming that they
    # indicate username and domain, respectively.
    
    # The script will not actually delete the maildir. I moves it
    # to a special directory which may once in a while be cleaned up
    # by the system administrator.
    
    # This script should be run as the user which owns the maildirs. If
    # the script is actually run by the apache user (e.g. through PHP),
    # then you could use "sudo" to grant apache the rights to run
    # this script as the relevant user.
    # Assume this script has been saved as
    # /usr/local/bin/postfixadmin-mailbox-postdeletion.sh and has been
    # made executable. Now, an example /etc/sudoers line:
    # apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postdeletion.sh
    # The line states that the apache user may run the script as the
    # user "courier" without providing a password.
    
    # Change this to where you keep your virtual mail users' maildirs.
    #basedir=/var/spool/maildirs ←コメントアウト
    basedir=/mail ←追記
    
    # Change this to where you would like deleted maildirs to reside.
    #trashbase=/var/spool/deleted-maildirs ←コメントアウト
    trashbase=/mail/.deleted-maildirs ← 追記
    
    if [ ! -e "$trashbase" ]; then
        echo "trashbase '$trashbase' does not exist; bailing out."
        exit 1
    fi
    
    if [ `echo $1 | fgrep '..'` ]; then
        echo "First argument contained a double-dot sequence; bailing out."
        exit 1
    fi
    if [ `echo $2 | fgrep '..'` ]; then
        echo "First argument contained a double-dot sequence; bailing out."
        exit 1
    fi
    
    #subdir=`echo "$1" | sed 's/@.*//'` ←コメントアウト
    subdir=$1 ← 追記
    
    maildir="${basedir}/$2/${subdir}"
    trashdir="${trashbase}/$2/`date +%F_%T`_${subdir}"
    
    parent=`dirname "$trashdir"`
    if [ ! -d "$parent" ]; then
        if [ -e "$parent" ]; then
            echo "Strainge - directory '$parent' exists, but is not a directory."
            echo "Bailing out."
            exit 1
        else
            mkdir -p "$parent"
            if [ $? -ne 0 ]; then
                echo "mkdir -p '$parent' returned non-zero; bailing out."
                exit 1
            fi
        fi
    fi
    
    if [ ! -e "$maildir" ]; then
        echo "maildir '$maildir' does not exist; nothing to do."
        exit 1
    fi
    if [ -e "$trashdir" ]; then
        echo "trashdir '$trashdir' already exists; bailing out."
        exit 1
    fi
    
    mv $maildir $trashdir
    
    exit $?

    ドメイン削除用スクリプトの編集

    # vi /usr/local/bin/postfixadmin/postfixadmin-domain-postdeletion.sh
    
    #!/bin/sh
    
    # Example script for removing a Maildir domain top-level folder
    # from a Courier-IMAP virtual mail hierarchy.
    
    # The script only looks at argument 1, assuming that it
    # indicates the relative name of a domain, such as
    # "somedomain.com". If $basedir/somedomain.com exists, it will
    # be removed.
    
    # The script will not actually delete the directory. I moves it
    # to a special directory which may once in a while be cleaned up
    # by the system administrator.
    
    # This script should be run as the user which owns the maildirs. If
    # the script is actually run by the apache user (e.g. through PHP),
    # then you could use "sudo" to grant apache the rights to run
    # this script as the relevant user.
    # Assume this script has been saved as
    # /usr/local/bin/postfixadmin-domain-postdeletion.sh and has been
    # made executable. Now, an example /etc/sudoers line:
    # apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-domain-postdeletion.sh
    # The line states that the apache user may run the script as the
    # user "courier" without providing a password.
    
    # Change this to where you keep your virtual mail users' maildirs.
    #basedir=/var/spool/maildirs ←コメントアウト
    basedir=/mail ←追記
    
    # Change this to where you would like deleted maildirs to reside.
    trashbase=/var/spool/deleted-maildirs ←コメントアウト
    trashbase=/mail/.deleted-maildirs ←追記
    
    if [ `echo $1 | fgrep '..'` ]; then
        echo "First argument contained a double-dot sequence; bailing out."
        exit 1
    fi
    
    if [ ! -e "$trashbase" ]; then
        echo "trashbase '$trashbase' does not exist; bailing out."
        exit 1
    fi
    
    trashdir="${trashbase}/`date +%F_%T`_$1"
    domaindir="${basedir}/$1"
    
    if [ ! -e "$domaindir" ]; then
        echo "Directory '$domaindir' does not exits; nothing to do."
        exit 0;
    fi
    if [ ! -d "$domaindir" ]; then
        echo "'$domaindir' is not a directory; bailing out."
        exit 1
    fi
    if [ -e "$trashdir" ]; then
        echo "Directory '$trashdir' already exits; bailing out."
        exit 1;
    fi
    
    mv $domaindir $trashdir
    
    exit $?

    実行権を与える

    # chmod 0700 /usr/local/bin/postfixadmin/postfixadmin*

    4)postfixadminの設定ファイルを修正

    # vi /var/www/postfixadmin/config.inc.php
    
    // Optional:
    // Script to run after creation of mailboxes.
    // Note that this may fail if PHP is run in "safe mode", or if
    // operating system features (such as SELinux) or limitations
    // prevent the web-server from executing external scripts.
    // $CONF['mailbox_postcreation_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postcreation.sh';
    $CONF['mailbox_postcreation_script']='sudo /usr/local/bin/postfixadmin/postfixadmin-mailbox-postcreation.sh'; ←追記
    
    // Optional:
    // Script to run after deletion of mailboxes.
    // Note that this may fail if PHP is run in "safe mode", or if
    // operating system features (such as SELinux) or limitations
    // prevent the web-server from executing external scripts.
    // $CONF['mailbox_postdeletion_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postdeletion.sh';
    $CONF['mailbox_postdeletion_script']='sudo /usr/local/bin/postfixadmin/postfixadmin-mailbox-postdeletion.sh'; ←追記
    
    // Optional:
    // Script to run after deletion of domains.
    // Note that this may fail if PHP is run in "safe mode", or if
    // operating system features (such as SELinux) or limitations
    // prevent the web-server from executing external scripts.
    // $CONF['domain_postdeletion_script']='sudo -u courier /usr/local/bin/postfixadmin-domain-postdeletion.sh';
    $CONF['domain_postdeletion_script']='sudo /usr/local/bin/postfixadmin/postfixadmin-domain-postdeletion.sh';

    5)sudo を使用するので/etc/sudoers を編集する。

    どうやら最近のマシンではエラーが出るらしいので併せて対処。
    エラーログは
    /etc/httpd/logs/error_log や /var/log/httpd/ssl_error_log 等のapacheのログ

    参考:sudoが「sudo: sorry, you must have a tty to run sudo」と文句を言うときは

    webサーバ(apache)のhttpd.conf設定は
    User apache
    Group apache
    としています。

    # visudo
    
    #
    # Disable "ssh hostname sudo ", because it will show the password in clear.
    #         You have to run "ssh -t hostname sudo ".
    #
    #Defaults    requiretty ←コメントアウト
    
    Defaults    env_reset
    Defaults    env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
                            LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
                            LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \
                            LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \
                            LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \
                            _XKB_CHARSET XAUTHORITY"
    
    ## Next comes the main part: which users can run what software on
    ## which machines (the sudoers file can be shared between multiple
    ## systems).
    ## Syntax:
    ##
    ##      user    MACHINE=COMMANDS
    ##
    ## The COMMANDS section may have other options added to it.
    ##
    ## Allow root to run any commands anywhere
    root    ALL=(ALL)       ALL
    # 以下を追記
    apache ALL=(ALL) NOPASSWD: /usr/local/bin/postfixadmin/postfixadmin-mailbox-postcreation.sh
    apache ALL=(ALL) NOPASSWD: /usr/local/bin/postfixadmin/postfixadmin-mailbox-postdeletion.sh
    apache ALL=(ALL) NOPASSWD: /usr/local/bin/postfixadmin/postfixadmin-domain-postdeletion.sh

    テスト

    postfixadminでメールアカウントの作成・削除を行って、該当のメールボックスの状況を確認する。

    ドメイン追加・削除を行う場合は、ドメインの追加後メールユーザーを1つ以上追加する必要がある。(ドメイン追加のみだとディレクトリが作成されない為)


    気になる事

    visudo でコメントアウトした

    #Defaults requiretty ←コメントアウト

    が、セキュリティー面でどうなのか、と。

    2011-01-14追記

    apacheユーザーなど 非シェルログインユーザーがsudoを実行できるようにするのに必要らしい。
    phpからsudoする時なども同様のようだ。







    2009 10月14日

    より新しい記事 2011-01-12
    http://perl.no-tubo.net/2011/01/06/メールサーバ構築のまとめ(複数のバーチャルド/

    CentOS5.3

    いろいろ構築した結果、メールサーバは Postfix +MySQL +Dovecot +postfixadmin で構成する事に決めた。
    postfixadminを使う利点は、

    • 複数のバーチャルドメインでの運用が可能&管理が楽
    • ドメインの追加やメールアドレスの追加がブラウザからGUIで出来る

    さらに、procmailとspamassassin、Clam AntiVirusを使って、スパムメール対策とウィルス対策も行う。

    バーチャルドメイン環境でprocmailとspamassassinを使うにコツがいる(らしい)

    ネットでの情報が少ない(ヒットしない)のでメモ。

    メールサーバの構築

    メールサーバの構築は メールサーバー構築(Postfix+Dovecot) – CentOSで自宅サーバー構築 を参考に行った。

    おやじさんのPostfixによるSMTPサーバの構築(RedHat標準版編)も参考になる。

    ウィルス対策

    ウィルス対策は アンチウィルスソフト導入(Clam AntiVirus) – CentOSで自宅サーバー構築 を参考に行った。

    スパムメール対策

    スパムメール対策は メールサーバーでウィルス&スパムチェック(Postfix+Clam AntiVirus+SpamAssassin) – CentOSで自宅サーバー構築 を参考に行った。

    postfixのMySQL対応化とpostfixadminの導入

    Postfixによるメールサーバ構築 (Postfix+MySQL+Dovecot+postfixadmin) を参考に行った。

    MySQL対応は CentOS5.3 PostfixをMySQL対応にするで行った。

    リンク先で作成した(cat となっているが vi 等で新規作成する事)

    /etc/postfix/mysql_virtual_alias_maps.cf
    /etc/postfix/mysql_virtual_domains_maps.cf
    /etc/postfix/mysql_virtual_mailbox_maps.cf
    /etc/postfix/mysql_virtual_mailbox_limit_maps.cf

    のファイルにはMySQLのパスワードが含まれているのでパーミッションの変更を行う事。

    chmod 640 /etc/postfix/mysql_*
    chown root.postfix /etc/postfix/mysql_*

    メールの保存は/mail 以下となる。

    だいたいうまくいくのだが、多少の変更が必要。

    spamassassinを有効にするにはprocmailでメールボックスに配送しなければならない。

    バーチャルドメインの場合procmailが使えないという記事が多かったので心配だったが、

    postfixのバーチャルドメイン管理でのspamフィルタについて

    を読むとどうやら使えるらしい。

    Postfixの設定

    main.cfの設定。

    http://centos.bungu-do.jp/2008/11/postfix_3_postfix.html のmain.cf 設定を少々変更。

    cp /etc/postfix/main.cf /etc/postfix/main.cf.org
    vi /etc/postfix/main.cf
    -------------------------------------------------------------------------------
    myhostname = mail.example.com ←自メールサーバFQDN
    mydomain = example.com ←自サーバドメイン
    #myorigin = $mydomain
    myorigin = $myhostname
    
    #inet_interfaces = localhost
    inet_interfaces = all
    
    #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    mydestination =
    
    #relay_domains = $mydestination
    relay_domains = $mydestination
    
    home_mailbox = Maildir/
    
    # IF YOU USE THIS TO DELIVER MAIL SYSTEM-WIDE, YOU MUST SET UP AN
    # ALIAS THAT FORWARDS MAIL FOR ROOT TO A REAL USER.
    #
    #mailbox_command = /some/where/procmail
    #mailbox_command = /some/where/procmail -a "$EXTENSION"
     mailbox_command = /usr/bin/procmail ←追記
    
    smtpd_banner = $myhostname ESMTP unknown
    
    local_transport = virtual
    # virtual_transport = virtual ←コメントアウト
    virtual_transport = procmail ←追記
    virtual_mailbox_base = /mail
    virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
    virtual_alias_domains = $virtual_alias_maps
    virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
    virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
    virtual_minimum_uid = 10000
    virtual_uid_maps = static:10000
    virtual_gid_maps = static:10000
    
    maximal_backoff_time = 800s
    minimal_backoff_time = 100s
    bounce_queue_lifetime = 60m
    maximal_queue_lifetime = 60m
    
    #mailbox_size_limit = 1024000000
    message_size_limit = 20480000
    
    #virtual_mailbox_limit = 51200000
    virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
    virtual_mailbox_limit_override = yes
    virtual_overquota_bounce = yes
    virtual_mailbox_limit_inbox = yes
    
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_type = dovecot
    smtpd_sasl_path = private/auth
    smtpd_sasl_local_domain = $myhostname
    smtpd_client_restrictions = reject_rbl_client bl.spamcop.net
    smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
    -------------------------------------------------------------------------------

    master.cfの設定。

    vi /etc/postfix/master.cf
    
    最終行に追記
    procmail unix - n n - - pipe
      flags=R user=vuser argv=/usr/bin/procmail -t -m USER=${user} DOMAIN=${nexthop} /etc/procmailrc

    procmailのルール、/etc/procmailrcを新規作成する。

    vi /etc/procmailrc
    
    SHELL=/bin/bash
    PATH=/usr/bin:/bin
    DEFAULT=/mail/$DOMAIN/$USER\@$DOMAIN/
    #LOGFILE=/mail/procmail.log
    LOGFILE=${DEFAULT}.procmail.log
    #LOCKFILE=/mail/procmail.lock
    LOCKFILE=/mail/$USER\@$DOMAIN.procmail.lock
    VERBOSE=ON
    
    :0fw
    |/usr/bin/spamc

    LOGFILEはテスト段階では/mail/procmail.logにしておくと楽。

    VERBOSE=ON は詳細ログを記録する設定なので本格運用する際にはコメントアウトする。

    また、LOCKFILEはユーザー数が増えた時の為に各ユーザーごとにロックファイルを使うようにしてみた。

    ログの肥大化を防ぐため、ログローテーション設定ファイル新規作成する。

    vi /etc/logrotate.d/procmail
    
    /mail/*/*/.procmail.log {
        missingok
        nocreate
        notifempty
    }

    注意点として、バーチャルドメインでの運用の場合ローカルユーザーのメールボックスにメールが配信されない。root宛のメールも然り。

    root宛のメールが普段使っているメールアドレス宛に配信されるようにしておく。

    vi /etc/aliases
    
    # Person who should get root's mail
    #root:          marc
    root:           myname@domain.com ←最終行に追加
    
    newaliases

    myname@domain.comにroot宛のメールが届くようになる。

    テスト

    メールを配信してみてヘッダ情報を見る。

    spamasassinが適用されていれば

    X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on xxx.xxxx.jp
    X-Spam-Level:
    X-Spam-Status: No, score=-0.1 required=13.0 tests=AWL,CONTENT_TYPE_PRESENT, ISO2022JP_BODY,ISO2022JP_CHARSET,X_MAILER_PRESENT autolearn=ham version=3.2.5

    Clam AntiVirusが適用されていれば

    X-Virus-Scanned: amavisd-new at xxxx.jp

    がヘッダ情報に挿入されているはず。

    その他のテスト方法は各リンクに掲載されていた通り。

    ユーザーメールディレクトリが作成されない

    ・・・なぜかメールディレクトリが作成されない。

    spamチェックのためメール配送をprocmailにするとディレクトリ作成されない事が判明。

    メール用ディレクトリは /mail 以下で、ユーザーが vuser 、グループが vuser 、パーミッションは0771。

    とりあえずユーザー postfix にセカンダリグループ vuserを追加してみたら既存のドメインには作成される。

    新規にドメイン追加>メールアドレス追加の場合は作成されない。

    この後したい事

    postfixadminでドメイン、メールユーザー等を削除した場合は各ディレクトリが削除されない。

    postfixadminのconfig.inc.phpにオプション設定があるが、シェルスクリプトで各動作が行えるようだ。

    シェルスクリプト・・・書けねぇ。。。

    postfixadminでメールボックスを削除する
    PostfixAdminのイケてないところ

    この辺に該当の対処が書かれている。

    cronを使って削除する方法のようだ。

    postfixadmin/ADDITIONS 内にある、

    postfixadmin-domain-postdeletion.sh
    postfixadmin-mailbox-postcreation.sh
    postfixadmin-mailbox-postdeletion.sh

    こいつらを使えば出来るかな?

    以下は分かりにくいのでまとめてみた

    postfixadmin +procmailな環境でメールディレクトリの作成・削除

    自動メールボックス作成に挑戦

    …つづきを読む







    2009 10月2日

    2010-12-04追記
    どうやらCentOS5.5ではRPMが用意されている模様
    64bit http://ftp.riken.jp/Linux/centos/5.5/centosplus/x86_64/RPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.x86_64.rpm
    32bit http://ftp.riken.jp/Linux/centos/5.5/centosplus/i386/RPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.i386.rpm
    あれ?前からあったのか??

    yumでインストールされていたらアンインストール

    yum erase postfix

    ダウンロード

    最新版の確認(/5.x/centosplus/SRPMS/より)

    rpm -ivh http://ftp.riken.jp/Linux/centos/5.4/centosplus/SRPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.src.rpm

    コンパイル前の下準備

    Postfix をMySQL対応にするためpostfix.specを編集。

    cd /usr/src/redhat/SPECS/
    vi postfix.spec
    ..
    %define MYSQL 1 ←確認(0なら1に修正)
    %define PGSQL 0 ←postgreSQLを使わないなら1から0に修正
    ..

    コンパイル

    srpmからrpmを作成する。

    エラー: ビルド依存性の失敗:
    pcre-devel は postfix-2.3.3-2.1.centos.mysql_pgsql.i386 に必要とされています

    などのエラーが出たら
    yum install pcre-devel
    でインストール後に再度実行。

    rpmbuild -bb postfix.spec

    インストール

    出来上がったRPMをインストールする。

    cd /usr/src/redhat/RPMS/i386/
    rpm -ivh postfix-2.3.3-2.1.centos.mysql_pgsql.i386.rpm

    yumの自動アップデートから外す

    yum update で postfix* なパッケージがアップデートされなくなる。

    これをしないとyumの自動アップデート時にMySQL非対応に戻ってしまう。

    vi /etc/yum.conf
    exclude=postfix* ←最終業に追記

    ↑手動でもやりましたけど
    Postfixをyumでアップデートしてしまった orz…