Postfix Adminでバーチャルなメールシステム構築

作成日: 2005/06/26
更新日: 2006/09/01

Debian Sarge では Postfix がバージョンアップしています。
それに合わせ Postfix Admin をインストールし、メールシステムをバーチャル化した実験を行いましたので、つたないレポートを公開します。諸兄の参考になれば幸いです。(
: 設定値は default 値を多用していますので、正規運用時にはセキュリティの観点から見直しください。)

前提条件:以下のシステムが稼働している状態で、インターナル・メールシステムを構築しました

・ Intel Pentium 3 Personal Computer
・ Linux Debian 3.1r0 Sarge
・ Apache 1.3.33
・ MySQL 4.1.11
・ PHP 4.3.10
・ php-mysql
・ postfix 2.1.5
・ courier-pop
・ Webmin 1.210

参考にしたサイト
・ 本家Postfix Admin (URL)
・ パソコンおやじ (URL)

S1 : Postfix Admin virtual server の指定
・httpd.conf の <Virtual Server Section>にサーバーを追加登録します
・注意点: Apache 1.3.33 の alias 指定に /images が新規登録してありますが、このまま使用するとPostfix Admin
のアイコン・イメージが表示されません。この部分をコメントアウトする必要があります。

ServerAdmin webmaster@fujiyama.ikezoe.net
DocumentRoot "/var/www/postfixadmin/public_html"
ServerName postfixadmin.ikezoe.net
<Directory /var/www/postfixadmin/public_html>
AllowOverride AuthConfig
</Directory>

S2 : Internal DNS へ Postfix Admin サーバーを追記する

S3 : postfixadmin ソフトウェアのダウンロードとインストール
本家サイトよりダウンロードしたファイルを解凍し、上記 Document Root の場所へコピーします。
インストール方法は、http://high5.net/postfixadmin/index.php?file=INSTALL.TXT を参照ください。Permission は 640 にしています

S4 : 指定ファイルの作成 (config.inc.php 修正)
Document root 内に config.inc.php.sample ファイルを config.inc.php へコピーし、内容を修正します。
config.inc.phpの内容:

<?php
//
// Postfix Admin
// by Mischa Peters <mischa at high5 dot net>
// Copyright (c) 2002 - 2005 High5!
// License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
//
// File: config.inc.php
//
if (ereg ("config.inc.php", $_SERVER['PHP_SELF']))
{
header ("Location: login.php");
exit;
}

// Postfix Admin Path
// Set the location to your Postfix Admin installation here.
$CONF['postfix_admin_url'] = 'https://postfixadmin.ikezoe.net';
$CONF['postfix_admin_path'] = '/var/www/postfixadmin/public_html';

// Language config
// Language files are located in './languages'.
$CONF['default_language'] = 'en';

// Database Config
// mysql = MySQL 3.23 and 4.0
// mysqli = MySQL 4.1
// pgsql = PostgreSQL
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';

// Site Admin
// Define the Site Admins email address below.
// This will be used to send emails from to create mailboxes.
$CONF['admin_email'] = 'postmaster@change-this-to-your.domain.tldfujiyama.ikezoe.net';

// Mail Server
// Hostname (FQDN) of your mail server.
// This is used to send email to Postfix in order to create mailboxes.
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';

// Encrypt
// In what way do you want the passwords to be crypted?
// md5crypt = internal postfix admin md5
// system = whatever you have set as your PHP system default
// cleartext = clear text passwords (ouch!)
$CONF['encrypt'] = 'md5crypt';

// Generate Password
// Generate a random password for a mailbox and display it.
// If you want to automagically generate paswords set this to 'YES'.
$CONF['generate_password'] = MD5;

// Page Size
// Set the number of entries that you would like to see
// in one page.
$CONF['page_size'] = '10';

// Default Aliases
// The default aliases that need to be created for all domains.
$CONF['default_aliases'] = array (
'abuse' => 'abuse@change-this-to-your.domain.tldfujiyama.ikezoe.net',
'hostmaster' => 'hostmaster@change-this-to-your.domain.tldfujiyama.ikezoe.net',
'postmaster' => 'postmaster@change-this-to-your.domain.tldfujiyama.ikezoe.net',
'webmaster' => 'webmaster@change-this-to-your.domain.tldfujiyama.ikezoe.net',
'root' => 'root@fujiyama.ikezoe.net' // add 2006/09/01
);

// Mailboxes
// If you want to store the mailboxes per domain set this to 'YES'.
// Example: /usr/local/virtual/domain.tld/username@domain.tld
$CONF['domain_path'] = 'NO';
// If you don't want to have the domain in your mailbox set this to 'NO'.
// Example: /usr/local/virtual/domain.tld/username
$CONF['domain_in_mailbox'] = 'YES';

// Default Domain Values
// Specify your default values below. Quota in MB.
$CONF['aliases'] = '10';
$CONF['mailboxes'] = '10';
$CONF['maxquota'] = '10';

// Quota
// When you want to enforce quota for your mailbox users set this to 'YES'.
$CONF['quota'] = 'NO';
// You can either use '1024000' or '1048576'
$CONF['quota_multiplier'] = '1024000';

// Transport
// If you want to define additional transport options for a domain set this to 'YES'.
// Read the transport file of the Postfix documentation.
$CONF['transport'] = 'NO';

// Virtual Vacation
// If you want to use virtual vacation for you mailbox users set this to 'YES'.
// NOTE: Make sure that you install the vacation module. http://high5.net/postfixadmin/
$CONF['vacation'] = 'NO';
// This is the autoreply domain that you will need to set in your Postfix
// transport maps to handle virtual vacations. It does not need to be a
// real domain (i.e. you don't need to setup DNS for it).
$CONF['vacation_domain'] = 'autoreply.change-this-to-your.domain.tld';

// Alias Control
// Postfix Admin inserts an alias in the alias table for every mailbox it creates.
// The reason for this is that when you want catch-all and normal mailboxes
// to work you need to have the mailbox replicated in the alias table.
// If you want to take control of these aliases as well set this to 'YES'.
$CONF['alias_control'] = 'NO';

// Special Alias Control
// Set to 'NO' if you don't want your domain admins to change the default aliases.
$CONF['special_alias_control'] = 'YES';

// Logging
// If you don't want logging set this to 'NO';
$CONF['logging'] = 'YES';

// Header
$CONF['show_header_text'] = 'NO';
$CONF['header_text'] = ':: Postfix Admin ::';

// Footer
// Below information will be on all pages.
// If you don't want the footer information to appear set this to 'NO'.
$CONF['show_footer_text'] = 'YESNO';
$CONF['footer_text'] = 'Return to change-this-to-your.domain.tld';
$CONF['footer_link'] = 'http://change-this-to-your.domain.tld';

// Welcome Message
// This message is send to every newly created mailbox.
// Change the text between EOM.
$CONF['welcome_text'] = <<<EOM
Hi,

Welcome to your new account.
EOM;

//
// END OF CONFIG FILE
//
?>

S5 : Postfix Admin のBasic認証化
Document root に配置した中に、.htaccess & htpasswd がありますので適宜修正します

S6 : setup.php で環境確認
http://postfixadmin.ikezoe.net/setup/ で確認してみましょう
以下のようなメッセージがでます。

Postfix Admin Setup Checker 1.0.0
Running software:
- PHP version 4.3.10-15
- Apache/1.3.33 (Debian GNU/Linux) PHP/4.3.10-15
Checking for dependencies:
- Magic Quotes: ON
- Depends on: presence config.inc.php - OK
- Depends on: MySQL 3.23, 4.0 - OK
- Depends on: session - OK
- Depends on: pcre - OK
Everything seems fine... you are ready to rock & roll!
Make sure you delete this setup.php file!
Also check the config.inc.php file for any settings that you might need to change!
Click here to go to the admin section (make sure that your .htaccess is setup properly)

S7 : MySQL へ postfix admin 用の空 DB とユーザーを作成
Webmin 1.210 を使用して、MySQL database Server を開きます
"Create new Database" で Database name を postfix と指定し、空DBを作成します
"Create new user" で username = postfix を作成します。

S8 : Postfix Admin 用テーブルの作成
ssh でログインします。
# sql -u root -p < ./DATABASE_MYSQL.TXT を実行すると config.inc.php で指定した内容を参照しながら
Postfix DB 内にテーブルを自動的に作成してくれます。

S9 : postfixadmin 用 virtual maildir の作成
postfixadmin が使用するLinux User / Goup を登録します。このケースでは、 "vuser" を
UID / GID # = 2001 で作成しました。この番号を後ほど main.cf ファイル等で使います。
/usr/local/virtual ディレクトリーを作成し、バーチャル・メール・システム用 maildir として使用します。user/group
は前述の vser を使用し、permissin を 771 としています。

S10 : virtual..*.cf 設定ファイルの作成
次の4つのファイルを /etc/postfix/ に作成します。Permission はすべて 640 です

[mysql_virtual_domains_maps.cf]

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain

[mysql_virtual_mailbox_maps.cf]

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username

[mysql_virtual_mailbox_limit_maps.cf]

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
additional_conditions = and active = '1'

[mysql_virtual_alias_maps.cf]

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

S11 : main.cf 設定ファイルの修正と追加
postfix 構成ファイルの /etc/postfix/main.cf にバーチャルの部分を追記します。

main.cf の内容:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4

myhostname = fujiyama.ikezoe.net
#alias_maps = hash:/etc/aliases
#alias_database = hash:/etc/aliases

myorigin = $myhostname
mydestination =
#relayhost = $mydomain
mynetworks = 127.0.0.0/8, 192.168.0.0/24
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
#recipient_delimiter = +
inet_interfaces = all
home_mailbox = Maildir/

# for virtual
local_transport = virtual

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:2001
virtual_mailbox_base = /usr/local/virtual
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 2001
virtual_transport = virtual
virtual_uid_maps = static:2001

virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_alias_domains = $virtual_alias_maps
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn
his diskspace quota, please try again later.
virtual_overquota_bounce = yes
alias_maps = $alias_database

ここまでの設定で postfixAdmin へログインしてみましょう。S5で修正しなければ、userid/password は admin / admin です。
始めに、Virtual Domain を作成します。(例 New Domain ボタンで fujiyama.ikezoe.net を追加)
次にユーザーの登録です。(例 Add Mailbox で fujiyama@fujiyama.ikezoe.net を追加)
Virtual List 開くと登録したものと config.inc.php で指定している postmaster 等の alias アカウントが表示されます。

S12 : master.cf 設定ファイルの修正
postfix 用 /etc/postfix/master.cf の以下の部分が "n" になっていないと、MySQL の
localhost 接続時にエラーしますので修正します。参照: http://forums.high5.net/index.php?showtopic=347

mater.cf の内容:

# ======================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (50)
# ======================================================
smtp inet n - n - - smtpd
cleanup unix n - n - 0 cleanup
rewrite unix - - n - - trivial-rewrite

ここまでの設定で、メールが /usr/locla/virtua/new 内に届いているはずです。まだ、メーラーからは取り出せません。

S13 : courier-authmysql のインストール
maildir/ からメールを取り出すためには、MySQL に登録された情報が必要です。この取り次ぎのプログラムをインストールします。
apt-get install courier-authmysql
/etc/courier/authmysqlrc を修正します。この修正時には、各値の設定区切りはTABキーになっています。スペースではありませんのでご注意ください。
参照 : http://forums.high5.net/index.php?showtopic=346

MYSQL_SERVER [TABキー] localhost
MYSQL_USERNAME[TABキー] postfix
MYSQL_PASSWORD[TABキー] postfix
MYSQL_PORT[TABキー] 0
MYSQL_OPT[TABキー] 0
MYSQL_DATABASE[TABキー]postfix
MYSQL_USER_TABLE[TABキー]mailbox
MYSQL_CRYPT_PWFIELD[TABキー] password
MYSQL_UID_FIELD[TABキー]'2001'
MYSQL_GID_FIELD[TABキー]'2001'
MYSQL_LOGIN_FIELD[TABキー]username
MYSQL_HOME_FIELD[TABキー]'/usr/local/virtual'
MYSQL_NAME_FIELD[TABキー]name
MYSQL_MAILDIR_FIELD[TABキー]maildir

/etc/courier/authdaemonrc を確認します。参照 : http://forums.high5.net/index.php?showtopic=1288

authdaemonrc の内容:

authmodulelist="authcustom authuserdb authmysql authpam"
authmodulelistorig="authcustom authuserdb authmysql authpam"
daemons=5
version="authdaemond.mysql"
authdaemonvar=/usr/local/var/authdaemon

S14 : メーラーのアカウント登録と受信
メーラーのアカウント登録を開き、ユーザー名はバーチャルなドメイン名を付加したユーザー名に修正します。(例 fujiyama@fujiyama.ikezoe.netなど)
受信できたらバーチャル・メール・システムの設置完了です。

[ 残っている作業 ]
正規運用時には、規定値でインストールした値の変更や暗号化の作業が必要です。

最近のブログ記事

Windows XPのOutlook Express 6.0 のスペルチェック
近所の会社の社長さんは Windows …
白菜の花
畑は春の陽気ですね。2/23以降朝の冷え…
css - リストの黒丸や四角の黒などが表示できない
比較的簡単なページを作成しています。リス…

おすすめ