設定ガイド · 1 min read · Oct 07, 2025

Postfix、Courier、MySQLを使用した仮想ユーザーとドメイン (Debian Etch) - ページ 3

6 Saslauthdの設定

まず実行します

mkdir -p /var/spool/postfix/var/run/saslauthd

次に、/etc/default/saslauthdを編集します。STARTをyesに設定し、OPTIONS=”-c”の行をOPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”に変更します:

vi /etc/default/saslauthd

| # # saslauthdデーモンの設定 # # saslauthdは起動時に自動的に実行されるべきですか? (デフォルト: no) START=yes # saslauthdはどの認証メカニズムを使用するべきですか? (デフォルト: pam) # # このDebianパッケージでの利用可能なオプション: # getpwent -- getpwent()ライブラリ関数を使用 # kerberos5 -- Kerberos 5を使用 # pam -- PAMを使用 # rimap -- リモートIMAPサーバーを使用 # shadow -- ローカルシャドウパスワードファイルを使用 # sasldb -- ローカルsasldbデータベースファイルを使用 # ldap -- LDAPを使用 (設定は/etc/saslauthd.confにあります) # # 一度に使用できるオプションは1つだけです。詳細についてはsaslauthdのマニュアルページを参照してください。 # # 例: MECHANISMS="pam" MECHANISMS="pam" # このメカニズムの追加オプション。 (デフォルト: なし) # メカニズム固有のオプションについてはsaslauthdのマニュアルページを参照してください。 MECH_OPTIONS="" # いくつのsaslauthdプロセスを実行するべきですか? (デフォルト: 5) # 値が0の場合、各接続のために新しいプロセスをフォークします。 THREADS=5 # その他のオプション (デフォルト: -c) # これらのオプションについての情報はsaslauthdのマニュアルページを参照してください。 # # Postfixユーザーの例: "-c -m /var/spool/postfix/var/run/saslauthd" # 注意: /usr/share/doc/sasl2-bin/README.Debianを参照してください OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r" |

次に、ファイル/etc/pam.d/smtpを作成します。以下の2行のみを含む必要があります(正しいデータベースの詳細を入力してください):

vi /etc/pam.d/smtp

| auth required pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 |

次に、ファイル/etc/postfix/sasl/smtpd.confを作成します。次のようになります:

vi /etc/postfix/sasl/smtpd.conf

| pwcheck_method: saslauthd mech_list: plain login allow_plaintext: true auxprop_plugin: mysql sql_hostnames: 127.0.0.1 sql_user: mail_admin sql_passwd: mail_admin_password sql_database: mail sql_select: select password from users where email = '%u' |

その後、PostfixとSaslauthdを再起動します:

/etc/init.d/postfix restart  
/etc/init.d/saslauthd restart

7 Courierの設定

次に、CourierにMySQLデータベースに対して認証するように指示する必要があります。まず、/etc/courier/authdaemonrcを編集し、authmodulelistの値を次のように変更します:

vi /etc/courier/authdaemonrc

| [...] authmodulelist="authmysql" [...] |

次に、/etc/courier/authmysqlrcのバックアップを作成し、古いファイルを空にします:

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig  
cat /dev/null > /etc/courier/authmysqlrc

次に、/etc/courier/authmysqlrcを開き、次の行を追加します:

vi /etc/courier/authmysqlrc

| MYSQL_SERVER localhost MYSQL_USERNAME mail_admin MYSQL_PASSWORD mail_admin_password MYSQL_PORT 0 MYSQL_DATABASE mail MYSQL_USER_TABLE users MYSQL_CRYPT_PWFIELD password #MYSQL_CLEAR_PWFIELD password MYSQL_UID_FIELD 5000 MYSQL_GID_FIELD 5000 MYSQL_LOGIN_FIELD email MYSQL_HOME_FIELD "/home/vmail" MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') #MYSQL_NAME_FIELD MYSQL_QUOTA_FIELD quota |

その後、Courierを再起動します:

/etc/init.d/courier-authdaemon restart  
/etc/init.d/courier-imap restart  
/etc/init.d/courier-imap-ssl restart  
/etc/init.d/courier-pop restart  
/etc/init.d/courier-pop-ssl restart

次のコマンドを実行することで

telnet localhost pop3

POP3サーバーが正しく動作しているか確認できます。+OK Hello there.と返答されるはずです。(quitと入力してLinuxシェルに戻ります。)

server1:/etc/postfix# telnet localhost pop3  
Trying 127.0.0.1...  
Connected to localhost.localdomain.  
Escape character is '^]'.  
+OK Hello there.  
quit  
+OK Better luck next time.  
Connection closed by foreign host.

8 /etc/aliasesの修正

次に、/etc/aliasesを開く必要があります。postmasterがrootを指し、rootが自分のユーザー名またはメールアドレスを指すことを確認してください。例えば、次のように:

vi /etc/aliases

| [...] postmaster: root root: [email protected] [...] |

/etc/aliasesを変更するたびに、次のコマンドを実行する必要があります

newaliases

その後、Postfixを再起動します:

/etc/init.d/postfix restart
Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。