GNU/Linux >> Linux の 問題 >  >> Debian

Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン(Debian Wheezy)

このチュートリアルは、Falko TimmeによるCopyright(c)2013です。これは、http://workaround.orgにあるChristophHaasのチュートリアルから派生しています。このチュートリアルは、クリエイティブコモンズライセンス2.5以降のバージョンで自由に使用できます。

このドキュメントでは、仮想ユーザーとドメイン、つまりMySQLデータベースにあるユーザーとドメインに基づくPostfixメールサーバーをインストールする方法について説明します。また、Courier(Courier-POP3、Courier-IMAP)のインストールと構成を示し、CourierがPostfixが使用するのと同じMySQLデータベースに対して認証できるようにします。

結果として得られるPostfixサーバーはSMTP-AUTHに対応しています およびTLS および割り当て (デフォルトでは、quotaはPostfixに組み込まれていません。Postfixに適切にパッチを適用する方法を説明します)。パスワードは暗号化で保存されます データベース内のフォーム(私が見つけたほとんどのドキュメントは、セキュリティリスクであるプレーンテキストのパスワードを扱っていました)。これに加えて、このチュートリアルでは Amavisdのインストールについて説明します。 、 SpamAssassin およびClamAV 電子メールがスパムやウイルスについてスキャンされるようにします。 SquirrelMailのインストール方法も紹介します ユーザーがメールを読んだり送信したり、パスワードを変更したりできるようにするためのウェブメールインターフェースとして。

このような「仮想」セットアップ(MySQLデータベース内の仮想ユーザーとドメイン)の利点は、「実際の」システムユーザーに基づくセットアップよりもはるかにパフォーマンスが高いことです。この仮想セットアップを使用すると、メールサーバーは数千のドメインとユーザーを処理できます。さらに、新しいユーザー/ドメインを追加したり、既存のユーザー/ドメインを編集したりするときにのみMySQLデータベースを処理する必要があるため、管理が容易です。 dbファイルを作成するためのpostmapコマンド、Postfixのリロードなどはもう必要ありません。MySQLデータベースの管理には、このハウツーにもインストールされるphpMyAdminなどのWebベースのツールを使用できます。 3番目の利点は、ユーザーがユーザー名として(ユーザー名+メールアドレスではなく)メールアドレスを持っていることです。これにより、理解しやすく、覚えやすくなります。

このハウツーは実用的なガイドとして意図されています。理論的背景については説明していません。それらは、Webの他の多くのドキュメントで扱われます。

このドキュメントには、いかなる種類の保証もありません。このようなシステムを構築する方法はこれだけではありません。この目標を達成する方法はたくさんありますが、これが私のやり方です。これがあなたのために働くという保証はありません!

1予備メモ

このチュートリアルはDebianWheezyに基づいているため、このチュートリアルを続行する前に、基本的なDebianWheezyサーバーのインストールをセットアップする必要があります。システムには静的IPアドレスが必要です。このチュートリアルでは、IPアドレスとして192.168.0.100を使用し、ホスト名としてserver1.example.comを使用しています。

/ bin/shを/bin/bashへのシンボリックリンクにすることが非常に重要です...

 dpkg-reconfigure dash 

デフォルトのシステムシェル(/ bin / sh)としてダッシュを使用しますか? <-いいえ

...そしてAppArmorを無効にすること:

 /etc/init.d/apparmor stop 
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

2 Postfix、Courier、Saslauthd、MySQL、phpMyAdminをインストールします

Postfix、Courier、Saslauthd、MySQL、およびphpMyAdminをインストールするには、単に実行します

 apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass 

いくつかの質問があります:

メール構成の一般的なタイプ:<-インターネットサイト
システムメール名:<-server1.example.com
MySQL「root」ユーザーの新しいパスワード:<-yourrootsqlpassword
繰り返しますMySQLの「root」ユーザーのパスワード:<-yourrootsqlpassword
Webベースの管理用のディレクトリを作成しますか? <-いいえ
SSL証明書が必要です<-OK
Webサーバーを自動的に再構成します:<-apache2
dbconfig-commonを使用してphpmyadminのデータベースを構成しますか? <-いいえ

3クォータパッチをPostfixに適用する

Postfixソースを取得し、クォータパッチでパッチを適用し、新しいPostfix .debパッケージをビルドして、それらの.debパッケージをインストールする必要があります。

 apt-get build-dep postfix 
 cd / usr / src 
apt-get source postfix

(次のコマンドで正しいPostfixバージョンを使用していることを確認してください。Postfix2.9.6がインストールされています。実行することでPostfixバージョンを確認できます

 postconf -d | grep mail_version 

出力は次のようになります。

 [メール保護]:/ usr / src#postconf -d | grep mail_version 
mail_version =2.9.6
milter_macro_v =$ mail_name $ mail_version
[email protected]:/ usr / src#

 wget http://vda.sourceforge.net/VDA/postfix-vda-v11-2.9.6.patch 
cd postfix-2.9.6
patch -p1 <../postfix- vda-v11-2.9.6.patch

次にdebian/rulesを開き、DEB_BUILD_HARDENINGを1から0に変更します:

 vi debian / rules 
 [...] export DEB_BUILD_HARDENING =0 [...] 

これを行わないと、ビルドが失敗し、次のエラーメッセージが表示されます。

 maildir.c:関数âdeliver_maildirâ:
maildir.c:974:17:エラー:フォーマットが文字列リテラルではなく、フォーマット引数がありません[-Werror =format-security]
maildir.c: 977:17:エラー:フォーマットが文字列リテラルではなく、フォーマット引数がありません[-Werror =format-security]
maildir.c:983:17:エラー:フォーマットが文字列リテラルではなく、フォーマット引数がありません[-Werror =format-security]
maildir.c:986:17:エラー:フォーマットは文字列リテラルではなく、フォーマット引数もありません[-Werror =format-security]
maildir.c:関数âsql2fileâ:
maildir.c:404:25:警告:属性warn_unused_resultで宣言されたâreadâの戻り値を無視します[-Wunused-result]
maildir.c:417:26:警告:属性で宣言されたâwriteâの戻り値を無視しますwarn_unused_result [-Wunused-result]
cc1:いくつかの警告がエラーとして扱われます
make:***[maildir.o]エラー1
make:ディレクトリ `/ usr / src/postfixを離れます-2.9.3 / src / virtual'
make [1]:***[update]エラー1
make [1]:ディレクトリ `/ usr / src/poを離れますstfix-2.9.3'
make:***[ビルド]エラー2
dpkg-buildpackage:エラー:debian /rulesビルドでエラー終了ステータス2が発生しました
[メール保護]:/ usr /src/postfix-2.9.3#

これで、新しいPostfix.debパッケージをビルドできます。

 dpkg-buildpackage 

ここで、1つのディレクトリを上に移動します。ここに、新しい.debパッケージが作成されています。

 cd .. 

コマンド

 ls -l <​​/ pre> 

利用可能なパッケージを表示します:

 [email protected]:/ usr / src#ls -l <​​br /> total 8400 
drwxr-xr-x 4 root root 4096 May 7 01:24 linux-headers-3.2.0-4- amd64
drwxr-xr-x 4 root root 4096 May 7 01:24 linux-headers-3.2.0-4-common
lrwxrwxrwx 1 root root 23 June 242012linux-kbuild-3.2->。 ./lib/linux-kbuild-3.2
drwxr-xr-x 18 root root 4096 Jul 1 21:13 postfix-2.9.6
-rw-r--r-- 1 root root 3561 Jul 1 21:13 postfix_2.9.6-2_amd64.changes
-rw-r--r-- 1 root root 1529980 Jul 1 21:13 postfix_2.9.6-2_amd64.deb
-rw-r-- r-- 1 root root 254432 Jul 1 21:12 postfix_2.9.6-2.diff.gz
-rw-r--r-- 1 root root 1492 Jul 1 21:12 postfix_2.9.6-2.dsc
-rw-r--r-- 1 root root 3767309 Mar 11 15:03 postfix_2.9.6.orig.tar.gz
-rw-r--r-- 1 root root 255470 Jul 1 21:13 postfix-cdb_2.9.6-2_amd64.deb
-rw-r--r-- 1 root root 367774 Jul 1 21:13 postfix-dev_2.9.6-2_all.deb
-rw- r--r-- 1 root root 1294258 Jul 1 21:13 postfix-doc_2.9.6-2_all.deb
-rw-r--r-- 1 root root 264196 Jul 1 21:13 postfix-ldap_2.9.6-2_amd64.deb
-rw-r--r-- 1 root root 257322 Jul 1 21:13 postfix-mysql_2.9.6-2_amd64.deb
-rw-r--r-- 1 root root 257376 Jul 1 21:13 postfix-pcre_2.9.6-2_amd64.deb
-rw-r--r-- 1 root root 257476 Jul 1 21: 13 postfix-pgsql_2.9.6-2_amd64.deb
-rw-r--r-- 1 root root 550009 May 7 08:47 postfix-vda-v11-2.9.6.patch
drwxr-xr -x 7 root root 4096 May 7 01:24 virtualbox-guest-4.1.18
[email protected]:/ usr / src#

postfixおよびpostfix-mysqlパッケージを選択し、次のようにインストールします。

 dpkg -i postfix_2.9.6-2_amd64.deb postfix-mysql_2.9.6-2_amd64.deb 

4 Postfix/Courier用のMySQLデータベースを作成する

次に、mailというデータベースを作成します:

 mysqladmin -u root -p create mail 

次に、MySQLシェルに移動します:

 mysql -u root -p 

MySQLシェルでは、メールデータベースに対するSELECT、INSERT、UPDATE、DELETE権限を持つpasswort mail_admin_password(独自のパスワードに置き換えます)を使用してユーザーmail_adminを作成します。このユーザーは、PostfixとCourierがメールデータベースに接続するために使用されます:

 GRANT SELECT、INSERT、UPDATE、DELETEONmail。*TO'mail_admin'@'localhost' IDENTIFIED BY'mail_admin_password'; 
GRANT SELECT、INSERT、UPDATE、DELETEONmail。*TO'mail_admin'@ 'localhost.localdomain' IDENTIFIED BY'mail_admin_password';
FLUSH PRIVILEGES;

引き続きMySQLシェルで、PostfixとCourierに必要なテーブルを作成します:

メールを使用;
 CREATE TABLEドメイン(
domain varchar(50)NOT NULL、
PRIMARY KEY(domain))
ENGINE =MyISAM;
 CREATE TABLE転送(
source varchar(80)NOT NULL、
destination TEXT NOT NULL、
PRIMARY KEY(source))
ENGINE =MyISAM;
 CREATE TABLEユーザー(
email varchar(80)NOT NULL、
password varchar(20)NOT NULL、
quote INT(10)DEFAULT '10485760'、
PRIMARY KEY(メール)
)ENGINE =MyISAM;
 CREATE TABLEトランスポート(
domain varchar(128)NOT NULL default''、
transport varchar(128)NOT NULL default''、
UNIQUE KEYドメイン(ドメイン)
)ENGINE =MyISAM;
終了;

お気づきかもしれませんが、やめます。コマンドMySQLシェルを終了し、Linuxシェルに戻りました。

ドメイン テーブルには、Postfixがメールを受信する必要がある各仮想ドメインが格納されます(例: example.com 。

ドメイン
example.com

転送 テーブルは、あるメールアドレスを別のメールアドレスにエイリアスするためのものです。 [メール保護]のメールを転送する [メール保護]

ソース 宛先
[メール保護] [メール保護]

ユーザー テーブルには、すべての仮想ユーザー(つまり、メールアドレスとユーザー名が同じであるためメールアドレス)とパスワード(暗号化)が格納されます。 form!)および各メールボックスのクォータ値(この例では、デフォルト値は10485760バイト、つまり10MBです)。

メール パスワード クォータ
[メール保護] No9.E4skNvGa。 (暗号化された形式の「秘密」) 10485760

トランスポート テーブルはオプションで、上級ユーザー向けです。これにより、単一ユーザー、ドメイン全体、またはすべてのメールのメールを別のサーバーに転送できます。たとえば、

ドメイン トランスポート
example.com smtp:[1.2.3.4]

example.comのすべてのメールを転送します SMTPプロトコルを介してIPアドレス 1.2.3.4を持つサーバーに接続します (角かっこ [] 「MXDNSレコードを検索しない」という意味です(これはIPアドレスにとって意味があります...)。代わりに完全修飾ドメイン名(FQDN)を使用する場合は、角かっこを使用しません。)

ところで、(メールサーバーシステムのIPアドレスは192.168.0.100だと思います)ブラウザでhttp://192.168.0.100/phpmyadmin/からphpMyAdminにアクセスし、mail_adminとしてログインできます。次に、データベースを確認できます。後で、phpMyAdminを使用してメールサーバーを管理できます。

5Postfixを設定する

次に、データベース内のすべての情報を見つけることができる場所をPostfixに通知する必要があります。したがって、6つのテキストファイルを作成する必要があります。 localhostではなくIPアドレス127.0.0.1でMySQLに接続するようにPostfixに指示していることに気付くでしょう。これは、Postfixがchroot jailで実行されており、Postfixにlocalhostを使用するように指示した場合に接続しようとするMySQLソケットにアクセスできないためです。 127.0.0.1を使用する場合、PostfixはTCPネットワークを使用してMySQLに接続しますが、これはchroot jailでも問題ありません(代わりに、MySQLソケットをchroot jailに移動すると、他の問題が発生します)。

/etc/mysql/my.cnfに次の行が含まれていることを確認してください:

 vi /etc/mysql/my.cnf 
 [...]#スキップネットワークの代わりに、デフォルトでは、互換性が高く安全性が低くないローカルホストでのみリッスンするようになりました。 bind-address =127.0.0.1 [...] 

/etc/mysql/my.cnfを変更する必要がある場合は、今すぐMySQLを再起動してください:

 /etc/init.d/mysql restart 

実行

 netstat -tap | grep mysql 

MySQLが127.0.0.1(localhost.localdomain)でリッスンしていることを確認するには:

 [メール保護]:/ usr / src#netstat -tap | grep mysql 
tcp 0 0 localhost.localdo:mysql *:* LISTEN 3895 / mysqld
[email protected]:/ usr / src#

それでは、6つのテキストファイルを作成しましょう。

 vi /etc/postfix/mysql-virtual_domains.cf 
 user =mail_adminpassword =mail_admin_passworddbname =mailquery =SELECT domain AS virtual FROM domain WHERE domain ='%s' hosts =127.0.0.1 
 vi /etc/postfix/mysql-virtual_forwardings.cf 
 user =mail_adminpassword =mail_admin_passworddbname =mailquery =SELECT destination FROM forwardings WHERE source ='%s' hosts =127.0.0.1 
 vi /etc/postfix/mysql-virtual_mailboxes.cf 
 user =mail_adminpassword =mail_admin_passworddbname =mailquery =SELECT CONCAT(SUBSTRING_INDEX(email、'@'、-1)、'/'、SUBSTRING_INDEX(email、 '@'、1)、'/')FROM users WHERE email ='%s' hosts =127.0.0.1 
 vi /etc/postfix/mysql-virtual_email2email.cf 
 user =mail_adminpassword =mail_admin_passworddbname =mailquery =SELECT email FROM users WHERE email ='%s' hosts =127.0.0.1 
 vi /etc/postfix/mysql-virtual_transports.cf 
 user =mail_adminpassword =mail_admin_passworddbname =mailquery =SELECTトランスポートFROMトランスポートWHEREドメイン='%s'ホスト=127.0.0.1 
 vi /etc/postfix/mysql-virtual_mailbox_limit_maps.cf 
 user =mail_adminpassword =mail_admin_passworddbname =mailquery =SELECT Quarter FROM users WHERE email ='%s' hosts =127.0.0.1 

次に、権限とこれらのファイルのグループを変更します。

 chmod o =/etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf

次に、ホームディレクトリ/ home/vmailを使用してvmailというユーザーとグループを作成します。これは、すべてのメールボックスが保存される場所です。

 groupadd -g 5000 vmail 
useradd -g vmail -u 5000 vmail -d / home / vmail -m

次に、Postfixの設定を行います。 server1.example.comを有効なFQDNに置き換えてください。そうしないと、Postfixが正しく機能しない可能性があります!

 postconf -e'myhostname =server1.example.com' 
postconf -e'mydestination =server1.example.com、localhost、localhost.localdomain'
postconf -e'mynetworks =127.0.0.0 / 8'
postconf -e' virtual_alias_domains ='
postconf -e' virtual_alias_maps =proxy:mysql:/ etc / postfix / mysql-virtual_forwardings.cf、mysql:/ etc / postfix/mysql-virtual_email2email。 cf'
postconf -e' virtual_mailbox_domains =proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'
postconf -e' virtual_mailbox_maps =proxy:mysql:/ etc / postfix/mysql-virtual_mailboxes。 cf'
postconf -e' virtual_mailbox_base =/ home / vmail'
postconf -e' virtual_uid_maps =static:5000'
postconf -e' virtual_gid_maps =static:5000'
postconf -e'smtpd_sasl_auth_enable =yes'
postconf -e'broken_sasl_auth_clients =yes'
postconf -e'smtpd_sasl_authenticated_header =yes'
postconf -e'smtpd_recipient_restrictions =permit_mynetworks、permit_sasl_>投稿conf -e'smtpd_use_tls =yes'
postconf -e'smtpd_tls_cert_file =/etc/postfix/smtpd.cert'
postconf -e'smtpd_tls_key_file =/etc/postfix/smtpd.key'
postconf -e'transport_maps =proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'
postconf -e'virtual_maildir_extended =yes'
postconf -e'virtual_mailbox_limit_maps =proxy:mysql:/ etc / postfix / mysql-virtual_mailbox_limit_maps.cf'
postconf -e' virtual_mailbox_limit_override =yes'
postconf -e' virtual_maildir_limit_message="到達しようとしているユーザーはクォータを超えています。"'
postconf- e'virtual_overquota_bounce =yes'
postconf -e'proxy_read_maps =$ local_recipient_maps $ mydestination $ virtual_alias_maps $ virtual_alias_domains $ virtual_mailbox_maps $ virtual_mailbox_domains $ virtual_>>

その後、TLSに必要なSSL証明書を作成します:

 cd / etc / postfix 
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509

国名(2文字のコード)[AU]:<-国名を入力します(例:「DE」)。
州名または州名(フルネーム)[一部の州]:<-州を入力しますまたは州名。
地域名(例:市)[]:<-市区町村を入力してください。
組織名(例:会社)[Internet Widgits Pty Ltd]:<-組織名を入力してください(例:会社名)
組織単位名(例:セクション)[]:<-組織単位名(例:「IT部門」)を入力します。
一般名(例:あなたの名前)[]:<-システムの完全修飾ドメイン名を入力します(例: "server1.example.com")。
メールアドレス[]:<-メールアドレスを入力します。

次に、smtpd.keyの権限を変更します:

 chmod o =/etc/postfix/smtpd.key 

6Saslauthdを構成する

最初の実行

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

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

 vi / etc / default / saslauthd 
 ## saslauthdデーモンの設定#詳細については、/ usr / share / doc / sasl2-bin/README.Debianをお読みください。##saslauthdを実行する必要があります起動時に自動的に? (デフォルト:no)START =yes#このsaslauthdインスタンスの説明。推奨。#(提案:SASL認証デーモン)DESC ="SASL認証デーモン"#このsaslauthdインスタンスの短縮名。強くお勧めします。#(提案:saslauthd)NAME ="saslauthd"#saslauthdはどの認証メカニズムを使用する必要がありますか? (デフォルト:pam)##このDebianパッケージで使用可能なオプション:#getpwent-getpwent()ライブラリ関数を使用します#kerberos5-Kerberos 5を使用します#pam-PAMを使用します#rimap-リモートIMAPサーバーを使用します#shadow- -ローカルシャドウパスワードfile#sasldbを使用します-ローカルsasldbデータベースfile#ldapを使用します-LDAPを使用します(構成は/etc/saslauthd.confにあります)##一度に使用できるオプションは1つだけです。詳細については、saslauthdのマニュアルページ#を参照してください。##例:MECHANISMS ="pam" MECHANISMS ="pam"#このメカニズムの追加オプション。 (デフォルト:なし)#mech固有のオプションについては、saslauthdのマニュアルページを参照してください。MECH_OPTIONS=""#実行するsaslauthdプロセスの数はいくつですか。 (デフォルト:5)#値0は、接続ごとに新しいプロセスをフォークします。THREADS=5#その他のオプション(デフォルト:-c -m / var / run / saslauthd)#注:-mオプションまたはsaslauthdは実行されません!##警告:-dオプションを指定しないでください。#-dオプションを指定すると、saslauthdがデーモンとしてではなくフォアグラウンドで実行されます。これにより、システムが正しく起動しなくなります。 #saslauthdをデバッグモードで実行したい場合は、安全のために手動で実行してください。## Debian固有の情報については、/ usr / share / doc / sasl2-bin / README.Debianを参照してください。#saslauthdのmanページを参照してください。これらのオプションに関する一般的な#情報の「saslauthd-h」の出力。## chroot Postfixユーザーの例: "-c -m / var / spool / postfix / var / run / saslauthd"#非chrootPostfixユーザーの例:"-c -m / var / run / saslauthd" ## Postfixがchrootを実行しているかどうかを確認するには、/ etc / postfix / master.cfを確認してください。#「smtpinet n --y---smtpd」という行がある場合または"smtpinet n --- --- smtpd"#の場合、Postfixはchrootで実行されています。#行が "smtp inet n --n --- smtpd"の場合、Postfixはchrootで実行されていません。 ="-c -m / var / run / saslauthd" 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 =1account十分なpam_mysql.souser=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:saslauthdmech_list:plain loginallow_plaintext:trueauxprop_plugin:sqlsql_engine:mysqlsql_hostnames:127.0.0.1sql_user:mail_adminsql_passwd:mail_admin_passwordsql_database:mailsql_select:select password from users '%[メール保護]%r' 

次に、postfixユーザーをsaslグループに追加します(これにより、Postfixがsaslauthdにアクセスする権限を持っていることを確認します):

 adduser postfix sasl 

次に、PostfixとSaslauthdを再起動します:

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

7クーリエの構成

次に、MySQLデータベースに対して認証する必要があることをCourierに通知する必要があります。まず、/ 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 localhostMYSQL_USERNAME mail_adminMYSQL_PASSWORD mail_admin_passwordMYSQL_PORT 0MYSQL_DATABASE mailMYSQL_USER_TABLE usersMYSQL_CRYPT_PWFIELDパスワード#MYSQL_CLEAR_PWFIELD passwordMYSQL_UID_FIELD 5000MYSQL_GID_FIELD 5000MYSQL_LOGIN_FIELD emailMYSQL_HOME_FIELD "" MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(電子メール、 '@'、vmail /ホーム/ -1)、'/'、SUBSTRING_INDEX(email、'@'、1)、'/')#MYSQL_NAME_FIELDMYSQL_QUOTA_FIELDクォータ

インストール中に、IMAP-SSLおよびPOP3-SSLのSSL証明書がホスト名localhostで作成されます。これを正しいホスト名(このチュートリアルではserver1.example.com)に変更するには、証明書を削除します...

 cd /etc/courier 
rm -f /etc/courier/imapd.pem
rm -f /etc/courier/pop3d.pem

...そして次の2つのファイルを変更します。 CN=localhostをCN=server1.example.comに置き換えます(必要に応じて他の値を変更することもできます):

 vi /etc/courier/imapd.cnf 
 [...] CN =server1.example.com [...] 
 vi /etc/courier/pop3d.cnf 
 [...] CN =server1.example.com [...] 

次に、証明書を再作成します...

 mkimapdcert 
mkpop3dcert

...そして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こんにちは。 (Linuxシェルに戻るには、quitと入力します。)

[メール保護]:/ etc / courier#telnet localhost pop3
127.0.0.1を試しています...
localhost.localdomainに接続しました。
エスケープ文字は「^]」です。
+OKこんにちは。
<-終了
+OK次回は頑張ってください。
外部ホストによって接続が閉じられました。
[メール保護]:/ etc / courier#

8 / etc/aliasesを変更します

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

 vi / etc / aliases 
 [...] postmaster:rootroot:postmaster [email protected] [...] 

またはこのように(管理者が自分のユーザー名の場合):

 [...] postmaster:rootroot:administrator [...] 

/ etc / aliasesを変更するときはいつでも、実行する必要があります

 newaliases 

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

 /etc/init.d/postfix restart 

9 amavisd-new、SpamAssassin、およびClamAVをインストールします

amavisd-new、spamassassin、およびclamavをインストールするには、次のコマンドを実行します。

 apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax 

その後、amavisd-newを構成する必要があります。構成は、/ etc / amavis/conf.dディレクトリにあるさまざまなファイルに分割されます。それらのそれぞれを見て、構成に慣れてください。ほとんどの設定は問題ありませんが、3つのファイルを変更する必要があります:

まず、@bypass_virus_checks_mapsと@bypass_spam_checks_mapsの行のコメントを解除して、/ etc / amavis / conf.d/15-content_filter_modeでClamAVとSpamAssassinを有効にする必要があります。

 vi /etc/amavis/conf.d/15-content_filter_mode 

ファイルは次のようになります:

 use strict;#このファイルを変更して、spamassassin#によるSPAMチェックを再度有効にし、アンチウイルスチェックを再度有効にすることができます。##デフォルトのアンチウイルスチェックmode#ウイルス対策チェックはデフォルトで無効になっていることに注意してください。#有効にする場合は、次の行のコメントを解除してください。スパムチェックモード#デフォルトではアンチウイルスチェックが無効になっていることに注意してください。#有効にする場合は、次の行のコメントを解除してください。; #定義されたリターンを確保する

次に、/ etc / amavis / conf.d/20-debian_defaultsにあるspam-/virus-mailsのスパム設定とアクションを確認する必要があります。デフォルト設定で問題がなければ、何も変更する必要はありません。ファイルには多くの説明が含まれているため、ここで設定を説明する必要はありません:

 vi /etc/amavis/conf.d/20-debian_defaults 
 [...] $ QUARANTINEDIR ="$ MYHOME / virusmails"; $ quarantine_subdir_levels =1; #隔離ディレクトリのハッシュを有効にする$ log_recip_templ =undef; #受信者ごとのレベル0ログエントリを無効にする$ DO_SYSLOG =1; #syslogd経由でログを記録(推奨)$ syslog_ident ='amavis'; #syslog identタグ、すべてのメッセージの前に追加$ syslog_facility ='mail'; $ syslog_priority ='debug'; #情報に切り替えてデバッグ出力などを削除します$ enable_db =1; #BerkeleyDB / libdb(SNMPおよびnanny)の使用を有効にする$ enable_global_cache =1; #$ enable_db =1 $ inet_socket_port =10024の場合、libdbベースのキャッシュの使用を有効にします。 #デフォルトのリスニングソケット$ sa_spam_subject_tag ='*** SPAM ***'; $ sa_tag_level_deflt =2.0; #そのレベル以上の場合、スパム情報ヘッダーを追加します$ sa_tag2_level_deflt =6.31; #そのレベルに「スパム検出」ヘッダーを追加$ sa_kill_level_deflt =6.31; #スパム回避アクションをトリガーします$ sa_dsn_cutoff_level =10; #DSNが送信されないスパムレベル[...] $ final_virus_destiny =D_DISCARD; #(データは失われません。ウイルス検疫を参照してください)$ final_banned_destiny =D_BOUNCE; #フロントエンドMTAの場合はD_REJECT $ final_spam_destiny =D_BOUNCE; $ final_bad_header_destiny =D_PASS; #誤検知が発生しやすい(スパムの場合)[...] 

最後に、/ etc / amavis / conf.d / 50-userを編集して、$ pax='pax';という行を追加します。真ん中:

 vi /etc/amavis/conf.d/50-user 
 usestrict;##ここに構成ディレクティブを配置します。これらは、以前のファイルの#をオーバーライドします。##このファイルで使用できるディレクティブのドキュメントと例については、/ usr / share / doc / amavisd-new /を参照してください#$ pax ='pax';#---- --------この行より下の部分は変更しないでください-------------1; #定義されたリターンを確保する

その後、これらのコマンドを実行して、clamavユーザーをamavisグループに追加し、amavisd-newとClamAVを再起動します。

 adduser clamav amavis 
/etc/init.d/amavis restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/clamav-daemon restart

次に、受信メールをamavisd-new経由でパイプするようにPostfixを設定する必要があります:

 postconf -e'content_filter =amavis:[127.0.0.1]:10024' 
postconf -e'receive_override_options =no_address_mappings'

その後、次の行を/etc/postfix/master.cfに追加します:

 vi /etc/postfix/master.cf 
 [...] amavis unix --- --- 2 smtp -o smtp_data_done_timeout =1200 -o smtp_send_xforward_command =yes127.0.0.1:10025 inet n ---- --smtpd -o content_filter =-o local_recipient_maps =-o relay_recipient_maps =-o smtpd_restriction_classes =-o smtpd_client_restrictions =-o smtpd_helo_restrictions =-o smtpd_sender_restrictions =-o smtpd_recipient_ o strict_rfc821_envelopes =yes -o receive_override_options =no_unknown_recipient_checks、no_header_body_checks 

次にPostfixを再起動します:

 /etc/init.d/postfix restart 

今すぐ実行

 netstat -tap 

そして、Postfix(マスター)がポート25(smtp)と10025でリッスンし、amavisd-newがポート10024でリッスンしているのが見えるはずです:

 [email protected]:/ etc / courier#netstat -tap 
アクティブなインターネット接続(サーバーと確立済み)
ProtoRecv-QSend-Qローカルアドレス外部アドレスIDプログラムP /> TCP 0 0 *:HTTP *:* LISTEN 6134 / apache2の
TCP 0 0 *:SSH *:* LISTEN 610 / sshdの
TCP 0 0 *:SMTP *:* 23128 /マスターをLISTEN
TCP 0 0 localhost.localdo:10024 *:* LISTEN 21937 /のamavisd-新しい(
TCP 0 0 localhost.localdo:10025 *:* LISTEN 23128 /マスター
TCP 0 0 localhost.localdo :mysql *:* LISTEN 4308 / mysqld
tcp 0 52 server1.example.com:ssh 192.168.0.206:57597 ESTABLISHED 976/0
*聞く610/sshd
tcp6 0 0 [::]:SMTP [::]:* LISTEN 23128 /マスター
にtcp6 0 [::]:IMAPS [::]:* LISTEN 18191 / couriertcpd
にtcp6 0 0: :]:pop3s              [::]:*                  LISTEN      18259/couriertcpd
tcp6       0      0 [::]:pop3               [::]:*                  LISTEN      18222/couriertcpd
tcp6       0      0 [::]:imap2 [::]:*                  LISTEN      18154/couriertcpd
[email protected]:/etc/courier#
 

10 Install Razor, Pyzor And DCC And Configure SpamAssassin

Razor, Pyzor and DCC are spamfilters that use a collaborative filtering network. To install Razor and Pyzor, run

apt-get install razor pyzor

DCC isn't available in the Debian Wheezy repositories, so we install it as follows:

cd /tmp
wget http://www.dcc-servers.net/dcc/source/dcc-dccproc.tar.Z
tar xzvf dcc-dccproc.tar.Z
cd dcc-dccproc-1.3.147
./configure --with-uid=amavis
make
make install
chown -R amavis:amavis /var/dcc
ln -s /var/dcc/libexec/dccifd /usr/local/bin/dccifd

Now we have to tell SpamAssassin to use these three programs. Edit /etc/spamassassin/local.cf and add the following lines to it:

vi /etc/spamassassin/local.cf
[...]#dccuse_dcc 1dcc_path /usr/local/bin/dccproc#pyzoruse_pyzor 1pyzor_path /usr/bin/pyzor#razoruse_razor2 1razor_config /etc/razor/razor-agent.conf#bayesuse_bayes 1use_bayes_rules 1bayes_auto_learn 1

Then we must enable the DCC plugin in SpamAssassin. Open /etc/spamassassin/v310.pre and uncomment the loadplugin Mail::SpamAssassin::Plugin::DCC line:

vi /etc/spamassassin/v310.pre
[...]# DCC - perform DCC message checks.## DCC is disabled here because it is not open source. See the DCC# license for more details.#loadplugin Mail::SpamAssassin::Plugin::DCC[...]

You can check your SpamAssassin configuration by executing:

spamassassin --lint

It shouldn't show any errors.

Restart amavisd-new afterwards:

/etc/init.d/amavis restart

Now we update our SpamAssassin rulesets as follows:

sa-update --no-gpg

We create a cron job so that the rulesets will be updated regularly.実行

 crontab -e 

to open the cron job editor. Create the following cron job:

23 4 */2 * * /usr/bin/sa-update --no-gpg &> /dev/null

This will update the rulesets every second day at 4.23h.

11 Quota Exceedance Notifications

If you want to get notifications about all the email accounts that are over quota, then create the file /usr/local/sbin/quota_notify:

cd /usr/local/sbin/
vi quota_notify
#!/usr/bin/perl -w# Author <[email protected]>## This script assumes that virtual_mailbox_base in defined# in postfix's main.cf file. This directory is assumed to contain# directories which themselves contain your virtual user's maildirs.# For example:## -----------/# |# |# home/vmail/domains/# | |# | |# example.com/ foo.com/# |# |# -----------------# | | |# | | |# user1/ user2/ user3/# |# |# maildirsize#use strict;my $POSTFIX_CF ="/etc/postfix/main.cf";my $MAILPROG ="/usr/sbin/sendmail -t";my $WARNPERCENT =80;my @POSTMASTERS =('[email protected]');my $CONAME ='My Company';my $COADDR ='[email protected]';my $SUADDR ='[email protected]';my $MAIL_REPORT =1;my $MAIL_WARNING =1;#get virtual mailbox base from postfix configopen(PCF, "<$POSTFIX_CF") or die $!;my $mboxBase;while () { next unless /virtual_mailbox_base\s*=\s*(.*)\s*/; $mboxBase =$1;}close(PCF);#assume one level of subdirectories for domain namesmy @domains;opendir(DIR, $mboxBase) or die $!;while (defined(my $name =readdir(DIR))) { next if $name =~ /^\.\.?$/; #skip '.' and '..' next unless (-d "$mboxBase/$name"); push(@domains, $name);}closedir(DIR);#iterate through domains for username/maildirsize filesmy @users;chdir($mboxBase);foreach my $domain (@domains) { opendir(DIR, $domain) or die $!; while (defined(my $name =readdir(DIR))) { next if $name =~ /^\.\.?$/; #skip '.' and '..' next unless (-d "$domain/$name"); push(@users, {"$name\@$domain" => "$mboxBase/$domain/$name"}); }}closedir(DIR);#get user quotas and percent usedmy (%lusers, $report);foreach my $href (@users) { foreach my $user (keys %$href) { my $quotafile ="$href->{$user}/maildirsize"; next unless (-f $quotafile); open(QF, "<$quotafile") or die $!; my ($firstln, $quota, $used); while () { my $line =$_; if (! $firstln) { $firstln =1; die "Error:corrupt quotafile $quotafile" unless ($line =~ /^(\d+)S/); $quota =$1; last if (! $quota); next; } die "Error:corrupt quotafile $quotafile" unless ($line =~ /\s*(-?\d+)/); $used +=$1; } close(QF); next if (! $used); my $percent =int($used / $quota * 100); $lusers{$user} =$percent unless not $percent; }}#send a report to the postmastersif ($MAIL_REPORT) { open(MAIL, "| $MAILPROG"); select(MAIL); map {print "To:$_\n"} @POSTMASTERS; print "From:$COADDR\n"; print "Subject:Daily Quota Report.\n"; print "DAILY QUOTA REPORT:\n\n"; print "----------------------------------------------\n"; print "| % USAGE | ACCOUNT NAME |\n"; print "----------------------------------------------\n"; foreach my $luser ( sort { $lusers{$b} <=> $lusers{$a} } keys %lusers ) { printf("| %3d | %32s |\n", $lusers{$luser}, $luser); print "---------------------------------------------\n"; } print "\n--\n"; print "$CONAME\n"; close(MAIL);}#email a warning to people over quotaif ($MAIL_WARNING) { foreach my $luser (keys (%lusers)) { next unless $lusers{$luser}>=$WARNPERCENT; # skip those under quota open(MAIL, "| $MAILPROG"); select(MAIL); print "To:$luser\n"; map {print "BCC:$_\n"} @POSTMASTERS; print "From:$SUADDR\n"; print "Subject:WARNING:Your mailbox is $lusers{$luser}% full.\n"; print "Reply-to:$SUADDR\n"; print "Your mailbox:$luser is $lusers{$luser}% full.\n\n"; print "Once your e-mail box has exceeded your monthly storage quota\n"; print "your monthly billing will be automatically adjusted.\n"; print "Please consider deleting e-mail and emptying your trash folder to clear some space.\n\n"; print "Contact <$SUADDR> for further assistance.\n\n"; print "Thank You.\n\n"; print "--\n"; print "$CONAME\n"; close(MAIL); }} 

Make sure that you adjust the variables at the top (especially the [email protected] email address).

We must make the file executable:

chmod 755 quota_notify

実行

 crontab -e 

to create a cron job for that script:

0 0 * * * /usr/local/sbin/quota_notify &> /dev/null

12 Test Postfix

To see if Postfix is ready for SMTP-AUTH and TLS, run

telnet localhost 25

After you have established the connection to your Postfix mail server type

ehlo localhost

If you see the lines

250-STARTTLS

および

250-AUTH PLAIN LOGIN

everything is fine:

[email protected]:/usr/local/sbin# telnet localhost 25
Trying ::1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (Debian/GNU)
<-- ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
<-- quit
221 2.0.0 Bye
Connection closed by foreign host.
[email protected]:/usr/local/sbin#

Type

終了

to return to the system shell.

13 Populate The Database And Test

データベースにデータを入力するには、MySQLシェルを使用できます:

 mysql -u root -p 
USE mail;

At least you have to create entries in the tables domains and users

INSERT INTO `domains` (`domain`) VALUES ('example.com');
INSERT INTO `users` (`email`, `password`, `quota`) VALUES ('[email protected]', ENCRYPT('secret'), 10485760);

(Please take care that you use the ENCRYPT syntax in the second INSERT statement in order to encrypt the password!)

If you want to make entries in the other two tables, that would look like this:

INSERT INTO `forwardings` (`source`, `destination`) VALUES ('[email protected]', '[email protected]');
INSERT INTO `transport` (`domain`, `transport`) VALUES ('example.com', 'smtp:mail.example.com');

To leave the MySQL shell, type

終了;

ほとんどの人にとって、MySQLのグラフィカルなフロントエンドがあれば簡単です。 therefore you can also use phpMyAdmin (in this example under http://192.168.0.100/phpmyadmin/ or http://server1.example.com/phpmyadmin/) to administrate the mail database. Again, when you create a user, go sure that you use the ENCRYPT function to encrypt the password:

I do not think I have to explain the domains and users table further.

The forwardings table can have entries like the following:

source destination  
[email protected] [email protected] Redirects emails for [email protected] to [email protected]
@example.com [email protected] Creates a Catch-All account for [email protected] All emails to example.com will arrive at [email protected], except those that exist in the users table (i.e., if [email protected] exists in the users table, mails to [email protected] will still arrive at [email protected]).
@example.com @anotherdomain.tld This redirects all emails to example.com to the same user at anotherdomain.tld. E.g., emails to [email protected] will be forwarded to [email protected]
[email protected] [email protected], [email protected] Forward emails for [email protected] to two or more email addresses. All listed email addresses under destination receive a copy of the email.

The transport table can have entries like these:

domain transport  
example.com : Delivers emails for example.com locally. This is as if this record would not exist in this table at all.
example.com smtp:mail.anotherdomain.tld Delivers all emails for example.com via smtp to the server mail.anotherdomain.com.
example.com smtp:mail.anotherdomain.tld:2025 Delivers all emails for example.com via smtp to the server mail.anotherdomain.com, but on port 2025, not 25 which is the default port for smtp.
example.com

smtp:[1.2.3.4]
smtp:[1.2.3.4]:2025
smtp:[mail.anotherdomain.tld]

The square brackets prevent Postfix from doing lookups of the MX DNS record for the address in square brackets. Makes sense for IP addresses.
.example.com smtp:mail.anotherdomain.tld Mail for any subdomain of example.com is delivered to mail.anotherdomain.tld.
* smtp:mail.anotherdomain.tld All emails are delivered to mail.anotherdomain.tld.
[email protected] smtp:mail.anotherdomain.tld Emails for [email protected] are delivered to mail.anotherdomain.tld.

See

man transport

for more details.

Please keep in mind that the order of entries in the transport table is important! The entries will be followed from the top to the bottom.

Important: Postfix uses a caching mechanism for the transports, therefore it might take a while until you changes in the transport table take effect. If you want them to take effect immediately, run

postfix reload

after you have made your changes in the transport table.

14 Send A Welcome Email For Creating Maildir

When you create a new email account and try to fetch emails from it (with POP3/IMAP) you will probably get error messages saying that the Maildir doesn't exist. The Maildir is created automatically when the first email arrives for the new account. Therefore it's a good idea to send a welcome email to a new account.

First, we install the mailx package:

apt-get install mailutils

To send a welcome email to [email protected], we do this:

mailx [email protected]

You will be prompted for the subject. Type in the subject (e.g. Welcome), then press ENTER, and in the next line type your message. When the message is finished, press ENTER again so that you are in a new line, then press CTRL+D; if you don't want to cc the mail, press ENTER again:

[email protected]:/usr/local/sbin# mailx [email protected]
Subject:Welcome <-- ENTER
Welcome! Have fun with your new mail account. <-- ENTER
<-- CTRL+D
Cc:<-- ENTER
[email protected]:/usr/local/sbin#

15 Installing SquirrelMail

SquirrelMail is a webmail interface that will let your users send and receive emails in a browser. This chapter shows how to install it and adjust it to our setup so that users can even change their email account password from the SquirrelMail interface.

To install SquirrelMail, we run:

apt-get install squirrelmail squirrelmail-compatibility php-pear php-db

Next we symlink the Apache configuration that comes with the SquirrelMail package to the /etc/apache2/conf.d directory and restart Apache:

ln -s /etc/squirrelmail/apache.conf /etc/apache2/conf.d/squirrelmail.conf
/etc/init.d/apache2 restart

SquirrelMail comes with some pre-installed plugins, unfortunately none of them is capable of letting us change our email password in our MySQL database. But there's the Change SQL Password plugin which we can install manually:

cd /usr/share/squirrelmail/plugins
wget http://www.squirrelmail.org/plugins/change_sqlpass-3.3-1.2.tar.gz
tar xvfz change_sqlpass-3.3-1.2.tar.gz
cd change_sqlpass
cp config.php.sample config.php

Now we must edit config.php and adjust it to our setup. Please adjust the $csp_dsn, $lookup_password_query, $password_update_queries, $password_encryption, $csp_salt_static, and $csp_delimiter variables as follows and comment out $csp_salt_query:

vi config.php
[...]$csp_dsn ='mysql://mail_admin:[email protected]/mail';[...]$lookup_password_query ='SELECT count(*) FROM users WHERE email ="%1" AND password =%4';[...]$password_update_queries =array('UPDATE users SET password =%4 WHERE email ="%1"');[...]$password_encryption ='MYSQLENCRYPT';[...]$csp_salt_static ='LEFT(password, 2)';[...]//$csp_salt_query ='SELECT salt FROM users WHERE username ="%1"';[...]$csp_delimiter ='@';[...]

The complete file looks as follows:

 * 2002-2005 Paul Lesneiwski <[email protected]> * This program is licensed under GPL. See COPYING for details * * @package plugins * @subpackage Change SQL Password * */ // Global Variables, don't touch these unless you want to break the plugin // global $csp_dsn, $password_update_queries, $lookup_password_query, $force_change_password_check_query, $password_encryption, $csp_salt_query, $csp_salt_static, $csp_secure_port, $csp_non_standard_http_port, $csp_delimiter, $csp_debug, $min_password_length, $max_password_length, $include_digit_in_password, $include_uppercase_letter_in_password, $include_lowercase_letter_in_password, $include_nonalphanumeric_in_password; // csp_dsn // // Theoretically, any SQL database supported by Pear should be supported // here. The DSN (data source name) must contain the information needed // to connect to your database backend. A MySQL example is included below. // For more details about DSN syntax and list of supported database types, // please see:// http://pear.php.net/manual/en/package.database.db.intro-dsn.php // //$csp_dsn ='mysql://user:[email protected]/email_users'; $csp_dsn ='mysql://mail_admin:[email protected]/mail'; // lookup_password_query // // This plugin will always verify the user's old password // against their login password, but an extra check can also // be done against the database for more security if you // desire. If you do not need the extra password check, // make sure this setting is empty. // // This is a query that returns a positive value if a user // and password pair are found in the database. // // This query should return one value (one row, one column), the // value being ideally a one or a zero, simply indicating that // the user/password pair does in fact exist in the database. // // %1 in this query will be replaced with the full username // (including domain), such as "[email protected]" // %2 in this query will be replaced with the username (without // any domain portion), such as "jose" // %3 in this query will be replaced with the domain name, // such as "example.com" // %4 in this query will be replaced with the current (old) // password in whatever encryption format is needed per other // plugin configuration settings (Note that the syntax of // the password will be provided depending on your encryption // choices, so you NEVER need to provide quotes around this // value in the query here.) // %5 in this query will be replaced with the current (old) // password in unencrypted plain text. If you do not use any // password encryption, %4 and %5 will be the same values, // except %4 will have double quotes around it and %5 will not. // //$lookup_password_query =''; // TERRIBLE SECURITY:$lookup_password_query ='SELECT count(*) FROM users WHERE username ="%1" AND plain_password ="%5"'; //$lookup_password_query ='SELECT count(*) FROM users WHERE username ="%1" AND crypt_password =%4'; $lookup_password_query ='SELECT count(*) FROM users WHERE email ="%1" AND password =%4'; // password_update_queries // // An array of SQL queries that will all be executed // whenever a password change attempt is made. // // Any number of queries may be included here. // The queries will be executed in the order given here. // // %1 in all queries will be replaced with the full username // (including domain), such as "[email protected]" // %2 in all queries will be replaced with the username (without // any domain portion), such as "jose" // %3 in all queries will be replaced with the domain name, // such as "example.com" // %4 in all queries will be replaced with the new password // in whatever encryption format is needed per other // plugin configuration settings (Note that the syntax of // the password will be provided depending on your // encryption choices, so you NEVER need to provide quotes // around this value in the queries here.) // %5 in all queries will be replaced with the new password // in unencrypted plain text - BEWARE! If you do not use // any password encryption, %4 and %5 will be the same // values, except %4 will have double quotes around it // and %5 will not. //// $password_update_queries =array(// 'UPDATE users SET crypt_password =%4 WHERE username ="%1"',// 'UPDATE user_flags SET force_change_pwd =0 WHERE username ="%1"',// 'UPDATE users SET crypt_password =%4, force_change_pwd =0 WHERE username ="%1"',// ); $password_update_queries =array('UPDATE users SET password =%4 WHERE email ="%1"'); // force_change_password_check_query // // A query that checks for a flag that indicates if a user // should be forced to change their password. This query // should return one value (one row, one column) which is // zero if the user does NOT need to change their password, // or one if the user should be forced to change it now. // // This setting should be an empty string if you do not wish // to enable this functionality. // // %1 in this query will be replaced with the full username // (including domain), such as "[email protected]" // %2 in this query will be replaced with the username (without // any domain portion), such as "jose" // %3 in this query will be replaced with the domain name, // such as "example.com" // //$force_change_password_check_query ='SELECT IF(force_change_pwd ="yes", 1, 0) FROM users WHERE username ="%1"'; //$force_change_password_check_query ='SELECT force_change_pwd FROM users WHERE username ="%1"'; $force_change_password_check_query =''; // password_encryption // // What encryption method do you use to store passwords // in your database? Please use one of the following, // exactly as you see it:// // NONE Passwords are stored as plain text only // MYSQLPWD Passwords are stored using the MySQL password() function // MYSQLENCRYPT Passwords are stored using the MySQL encrypt() function // PHPCRYPT Passwords are stored using the PHP crypt() function // MD5CRYPT Passwords are stored using encrypted MD5 algorithm // MD5 Passwords are stored as MD5 hash // //$password_encryption ='MYSQLPWD'; $password_encryption ='MYSQLENCRYPT'; // csp_salt_query // csp_salt_static // // Encryption types that need a salt need to know where to get // that salt. If you have a constant, known salt value, you // should define it in $csp_salt_static. Otherwise, leave that // value empty and define a value for the $csp_salt_query. // // Leave both values empty if you do not need (or use) salts // to encrypt your passwords. // // The query should return one value (one row, one column) which // is the salt value for the current user's password. This // query is ignored if $csp_salt_static is anything but empty. // // %1 in this query will be replaced with the full username // (including domain), such as "[email protected]" // %2 in this query will be replaced with the username (without // any domain portion), such as "jose" // %3 in this query will be replaced with the domain name, // such as "example.com" // //$csp_salt_static ='LEFT(crypt_password, 2)'; //$csp_salt_static ='"a4"'; // use this format with MYSQLENCRYPT //$csp_salt_static ='$2$blowsomefish$'; // use this format with PHPCRYPT //$csp_salt_static =''; $csp_salt_static ='LEFT(password, 2)'; //$csp_salt_query ='SELECT SUBSTRING_INDEX(crypt_password, '$', 1) FROM users WHERE username ="%1"'; //$csp_salt_query ='SELECT SUBSTRING(crypt_password, (LENGTH(SUBSTRING_INDEX(crypt_password, '$', 2)) + 2)) FROM users WHERE username ="%1"'; //$csp_salt_query ='SELECT salt FROM users WHERE username ="%1"'; //$csp_salt_query =''; // csp_secure_port // // You may ensure that SSL encryption is used during password // change by setting this to the port that your HTTPS is served // on (443 is typical). Set to zero if you do not wish to force // an HTTPS connection when users are changing their passwords. // // You may override this value for certain domains, users, or // service levels through the Virtual Host Login (vlogin) plugin // by setting a value(s) for $vlogin_csp_secure_port in the vlogin // configuration. // $csp_secure_port =0; //$csp_secure_port =443; // csp_non_standard_http_port // // If you serve standard HTTP web requests on a non-standard // port (anything other than port 80), you should specify that // port number here. Set to zero otherwise. // // You may override this value for certain domains, users, or // service levels through the Virtual Host Login (vlogin) plugin // by setting a value(s) for $vlogin_csp_non_standard_http_port // in the vlogin configuration. // //$csp_non_standard_http_port =8080; $csp_non_standard_http_port =0; // min_password_length // max_password_length // include_digit_in_password // include_uppercase_letter_in_password // include_lowercase_letter_in_password // include_nonalphanumeric_in_password // // You can set the minimum and maximum password lengths that // you accept or leave those settings as zero to indicate that // no limit should be applied. // // Turn on any of the other settings here to check that the // new password contains at least one digit, upper case letter, // lower case letter and/or one non-alphanumeric character. // $min_password_length =6; $max_password_length =0; $include_digit_in_password =0; $include_uppercase_letter_in_password =0; $include_lowercase_letter_in_password =0; $include_nonalphanumeric_in_password =0; // csp_delimiter // // if your system has usernames with something other than // an "@" sign separating the user and domain portion, // specify that character here // //$csp_delimiter ='|'; $csp_delimiter ='@'; // debug mode // $csp_debug =0;?>

Now we must go into the SquirrelMail configuration and tell SquirrelMail that we use Courier as our POP3 and IMAP server and enable the Change SQL Password and the Compatibility plugins:

/usr/sbin/squirrelmail-configure

You'll see the following menu. Navigate through it as indicated:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C   Turn color on
S   Save data
Q   Quit

Command >> <-- D


SquirrelMail Configuration : Read: config.php
---------------------------------------------------------
While we have been building SquirrelMail, we have discovered some
preferences that work better with some servers that don't work so
well with others. If you select your IMAP server, this option will
set some pre-defined settings for that server.

Please note that you will still need to go through and make sure
everything is correct.これによってすべてが変わるわけではありません。 There are
only a few settings that this will change.

Please select your IMAP server:
    bincimap    = Binc IMAP server
    courier     = Courier IMAP server
    cyrus       = Cyrus IMAP server
    dovecot     = Dovecot Secure IMAP server
    exchange    = Microsoft Exchange IMAP server
    hmailserver = hMailServer
    macosx      = Mac OS X Mailserver
    mercury32   = Mercury/32
    uw          = University of Washington's IMAP server
    gmail       = IMAP access to Google mail (Gmail) accounts

    quit        = Do not change anything
Command >> <-- courier


              imap_server_type = courier
         default_folder_prefix = INBOX.
                  trash_folder = Trash
                   sent_folder = Sent
                  draft_folder = Drafts
            show_prefix_option = false
          default_sub_of_inbox = false
show_contain_subfo lders_option = false
            optional_delimiter = .
                 delete_folder = true

Press enter to continue... <-- press ENTER


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C   Turn color on
S   Save data
Q   Quit

Command >> <-- 8


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
  Installed Plugins
    1. view_as_html

  Available Plugins:
    2. administrator
    3. bug_report
    4. calendar
    5. change_sqlpass
    6. compatibility
    7. delete_move_next
    8. demo
    9. filters
    10. fortune
    11. info
    12. listcommands
    13. mail_fetch
    14. message_details
    15. newmail
    16. sent_subfolders
    17. spamcop
    18. squirrelspell
    19. test
    20. translate

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >> <-- 6 (or whatever number the compatibility plugin has - it's n eeded by the change_sqlpass plugin)


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
  Installed Plugins
    1. view_as_html
    2. compatibility

  Available Plugins:
    3. administrator
    4. bug_report
    5. calendar
    6. change_sqlpass
    7. delete_move_next
    8. demo
    9. filters
    10. fortune
    11. info
    12. listcommands
    13. mail_fetch
    14. message_details
    15. newmail
    16. sent_subfolders
    17. spamcop
    18. squirrelspell
    19. test
    20. translate

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >> <-- 6 (the number of the change_sqlpass plugin)


SquirrelMail Configuration : Read: config.php (1.4.0)
------------------------------------------- --------------
Plugins
  Installed Plugins
    1. view_as_html
    2. compatibility
    3. change_sqlpass

  Available Plugins:
    4. administrator
    5. bug_report
    6. calendar
    7. delete_move_next
    8. demo
    9. filters
    10. fortune
    11. info
    12. listcommands
    13. mail_fetch
    14. message_details
    15. newmail
    16. sent_subfolders
    17. spamcop
    18. squirrelspell
    19. test
    20. translate

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >> <-- S


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
  Installed Plugins
    1. view_as_html
    2. compatibility
    3. change_sqlpass

  Available Plugins:
    4. administrator
    5 . bug_report
    6. calendar
    7. delete_move_next
    8. demo
    9. filters
    10. fortune
    11. info
    12. listcommands
    13. mail_fetch
    14. message_details
    15. newmail
    16. sent_subfolders
    17. spamcop
    18. squirrelspell
    19. test
    20. translate

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >> S

Data saved in config.php
Press enter to continue... <-- press ENTER


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
  Installed Plugins
    1. view_as_html
    2. compatibility
    3. change_sqlpass

  Available Plugins:
    4. administrator
    5. bug_report
    6. calendar
    7. delete_move_next
    8. demo
    9. filters
    10. fort une
    11. info
    12. listcommands
    13. mail_fetch
    14. message_details
    15. newmail
    16. sent_subfolders
    17. spamcop
    18. squirrelspell
    19. test
    20. translate

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >> <-- Q

Now you can type in http://server1.example.com/squirrelmail or http://192.168.0.100/squirrelmail in your browser to access SquirrelMail.

Log in with your email address (e.g. [email protected]) and your password:

You should find the welcome email in your inbox:

To change your password, go to Options and then select Change Password:

Type in your current password and then your new password twice:

If the password has been changed successfully, you will see the following error message which means you must log in again with your new password (because the old one isn't active anymore):

16 VMA (Virtual Mail Admin Interface)

Virtual Mail Admin (VMA) is a small PHP-based web app written to manage the email system set up in this guide. I didn't test it, but I thought I'd share.

This is what the developer (Charl Loubser) wrote to me in an email:

"Hi There,

I don't know if you'll like this, or if this has any use to you, but I thought I'd Share:

I wrote a silly little webapp for the setup you did in the Howto:https://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu-10.04

If you approve and think it worthy of sharing on your tutorial, you are more than welcome, and can feel free to do so.

As mentioned in the readme, this is not a perfect app, but it does the job for now, and I'd thing it's relatively safe in a closed environment (LAN setup between servers).

The rar file with the app is attached, but can also be downloaded at :http://code.google.com/p/vma/"

17 References

  • Tutorial:ISP-style Email Service with Debian-Sarge and Postfix 2.1:http://workaround.org/articles/ispmail-sarge/
  • Postfix + Quota:http://vhcs.net/new/modules/newbb/viewtopic.php?topic_id=3496&forum=17
  • Mail Passwords Encrypted using saslauthd:http://www.syscp.de/docs/public/contrib/cryptedmailpws

  • Postfix MTA:http://www.postfix.org/
  • Postfix Quota Patch:http://web.onda.com.br/nadal/
  • phpMyAdmin:http://www.phpmyadmin.net/
  • SquirrelMail:http://www.squirrelmail.org/
  • Debian:http://www.debian.org/
  • Virtual Mail Admin Interface (VMA):http://code.google.com/p/vma/

Debian
  1. Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン(Ubuntu 14.04LTS)

  2. Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン(Ubuntu 13.10)

  3. Sendmailを使用した仮想ユーザーとドメイン

  1. Postfix、Courier、MySQLを使用した仮想ユーザーとドメイン(Ubuntu 6.10 Edgy Eft)

  2. ISPConfigとcourier/postfixを使用したDebian6SqueezeからDebian7Wheezyへのアップグレード

  3. CentOS6VPSでPostfixとDovecotを使用する仮想ユーザーとドメインを備えたメールサーバー

  1. Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン(Ubuntu 8.04 LTS)

  2. Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン(Ubuntu 8.10)

  3. Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン(Ubuntu 10.04)