MAIL (Courier-MTA) Server

CentOS 8にメールサーバー構築(Courier-MTA)

Courier-MTAについて

Courier-MTA(クーリエエムティーエー)は、メールサーバを構築する際に必要な「送信:SMTP」「受信:POP3」「受信:IMAP4」などの各種メールサービスのオールインワンでまとめたオープンソースのパッケージで、公式WEBでは「Courier Mail Server」と呼ばれています。

サーバーにメールを保存してPCやスマホなどのクライアントからメールを見に行く受信方法「IMAP」を提供するパッケージの「Courier-IMAP」は超有名(他にこれ以上のものが無い)なのですが、MTAパッケージとしてはかなりマイナーで、日本国内では解説している手順も少ないため、構築難易度は本ブログの手順の中でも高い部類に入ります。

スパム対策、ウィルス対策含め Courier-MTA の構築が出来るようになれば、恐らく大概のLinuxサーバーの構築は出来るようになるので、頑張ってトライしてみましょう!

 

MTAとは

MTA(Mail Transport Agent)はメール転送エージェントで主にメールサーバーに届いた情報を必要な場所に送信する郵便局のような役割を果たします。

一般的にメールサーバー構築時はqmail やPostfix、Sendmailなどのメールサービス用の各種パッケージを組み合わせて構築をしますが、Courier-MTAはメールサービスに必要なすべてのパッケージがバンドルされており一体感があるため、一度手順を覚えてしまえばとても扱い易いのです。

 

▼公式WEB
http://www.courier-mta.org/

 

構築環境

  • CentOS Linux release 8.2.2004 (Core)
  • courier-1.0.14
  • courier-authlib-0.71.0
  • courier-unicode-2.1
  • ルータで「ポート 110、143、587、25」を開放

 

 

ルータのポート開放でメール送受信に必要な通信を受け入れる

メールサーバーの構築を行う前に、サーバー側NWのルータのポートを開放して、外部からの通信がサーバーに届くようにします。
メールサーバーは用途ごとに解放するポート番号が複数あります。

ポートの設定方法はルータによって違いますが、概ね下記のような感じです。

 

用途 プロトコル 開始ポート 終了ポート サーバーのローカルアドレス
受信:POP3 TCP/UDP 110 110 192.168.x.x
受信:IMAP TCP/UDP 143 143 192.168.x.x
送信:SMTP TCP/UDP 587 587 192.168.x.x
送信:SMTP TCP/UDP 25 25 192.168.x.x

 

▼通信イメージ

 

 

▼ルータの設定イメージ

 

 

事前準備

Courier-MTAはリポジトリにRPMパッケージ等が展開されておらずソースコードのみのため、一度ソースコードを元にRPMにパッケージ化した後インストールします。
CentOS 8の最小インストールでは下記のコマンドが無いのでインストールします。

rpmbuild ソースコードを元にコンパイルからRPMパッケージ化まで行う行ってくれるコマンドです。
wget インターネット上からURL指定でファイルをダウンロードするコマンドです。

 

▼rpmbuildコマンドのパッケージ確認

CentOS 8 では dnf コマンドを利用してパッケージ情報検索やインストール、削除を行うことができます。
パッケージファイルが管理されているダウンロードサーバーをリポジトリと呼び、新規でリポジトリを追加することで、ダウンロードできるファイルの種類を増やすことが可能です。


 command
# dnf list | grep rpm-build
rpm-build-libs.x86_64 4.14.2-37.el8 @anaconda
rpm-build.x86_64 4.14.2-37.el8 AppStream
rpm-build-libs.i686

 

rpmbuildコマンドのインストール

「-y」オプションを指定すると、インストール可否の確認で「yes」となり自動的にインストールが開始します。


 command
# dnf install -y rpm-build

 

▼wgetコマンドの確認

 command
# dnf list | grep wget
wget.x86_64

 

▼wgetコマンドのインストール

 command
# dnf install -y wget

 

▼コマンドがインストールされたか確認

 command
# which wget
/usr/bin/wget
# which rpmbuild
/usr/bin/rpmbuild

 

 

courier-MTA関連ファイルのDL

▼必要なパッケージ

CourierMailServer SMTP(送信)、POP(受信)等のメールサービスに必要なサーバー含め、IMAPも提供可能なオールインワンパッケージ。
courier-unicode courierをunicodeに対応させるためのライブラリ。
courier-authlib Courierアプリケーションに認証サービスを提供するためのライブラリ。

 

 

courier-authlibインストール

courier-authlibはメール送受信のユーザー認証に使われる拡張パッケージです。
CourierMailServerのインストールより先に行います。

 

▼wgetでcourier-authlibのDL
先ほどcourier-unicodeをDLしたフォルダに移動後同じようにwgetでDLします。

 command
# wget https://sourceforge.net/projects/courier/files/authlib/0.71.0/courier-authlib-0.71.0.tar.bz2
# ls -l
合計 2600
-rw-r--r-- 1 root root 2207895 6月 18 10:08 courier-authlib-0.71.0.tar.bz2
-rw-r--r-- 1 root root 447917 9月 18 2018 courier-unicode-2.1.tar.bz2

 

▼courier-authlibのrpm化

 command
# rpmbuild -tb courier-authlib-0.71.0.tar.bz2
エラー: ビルド依存性の失敗:
/usr/include/ltdl.h は courier-authlib-0.71.0-1.el8.x86_64 に必要とされています
libtool は courier-authlib-0.71.0-1.el8.x86_64 に必要とされています
mysql-devel は courier-authlib-0.71.0-1.el8.x86_64 に必要とされています
postgresql-devel は courier-authlib-0.71.0-1.el8.x86_64 に必要とされています
sqlite-devel は courier-authlib-0.71.0-1.el8.x86_64 に必要とされています
zlib-devel は courier-authlib-0.71.0-1.el8.x86_64 に必要とされています

このように依存関係で必要なパッケージのエラーが表示された場合は、上記のパッケージをインストールしてから再度rpmbuildを行います。
依存関係のあるパッケージのインストール方法例については、後に開設する CourierMailServerで必要なパッケージのインストール方法 の手順を参照。

 

下記dnfコマンドのように必要なパッケージを一気に入れることも可能です。

 command
# dnf -y install /usr/include/ltdl libtool mysql-devel postgresql-devel sqlite-devel zlib-devel

 

▼書き出されたRPMファイルの確認
rpmbuild実行後は、一般ユーザーの /home/username/rpmbuild にパッケージが書き出されます。

 command
# cd ~/rpmbuild/RPMS/x86_64/
# ls -lrt | grep authlib
-rw-r--r-- 1 root root 160992 10月 3 16:39 courier-authlib-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 53484 10月 3 16:39 courier-authlib-devel-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 42528 10月 3 16:39 courier-authlib-userdb-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 45596 10月 3 16:39 courier-authlib-ldap-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 33376 10月 3 16:39 courier-authlib-mysql-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 27648 10月 3 16:39 courier-authlib-sqlite-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 30380 10月 3 16:39 courier-authlib-pgsql-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 13980 10月 3 16:39 courier-authlib-pipe-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 101112 10月 3 16:39 courier-authlib-debugsource-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 294800 10月 3 16:39 courier-authlib-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 13400 10月 3 16:39 courier-authlib-devel-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 52280 10月 3 16:39 courier-authlib-userdb-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 341764 10月 3 16:39 courier-authlib-ldap-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 250168 10月 3 16:39 courier-authlib-mysql-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 170368 10月 3 16:39 courier-authlib-sqlite-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 192364 10月 3 16:39 courier-authlib-pgsql-debuginfo-0.71.0-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 17684 10月 3 16:39 courier-authlib-pipe-debuginfo-0.71.0-1.el8.x86_64.rpm

 

authlibは大量にファイルが出力されますが、必要なライブラリは下記の3つです。

  • courier-authlib-0.71.0-1.el8.x86_64.rpm
  • courier-authlib-devel-0.71.0-1.el8.x86_64.rpm
  • courier-authlib-userdb-0.71.0-1.el8.x86_64.rpm

 

▼必要なRPMファイルのインストール
下記3つのライブラリのみインストール。

 command
# rpm -ivh courier-authlib-0.71.0-1.el8.x86_64.rpm
# rpm -ivh courier-authlib-devel-0.71.0-1.el8.x86_64.rpm
# rpm -ivh courier-authlib-userdb-0.71.0-1.el8.x86_64.rpm

 

 

courier-unicode のインストール

▼wgetで「courier-unicode」をDL

 command
# cd /home/username/任意の作業TMPフォルダに移動
# wget https://sourceforge.net/projects/courier/files/courier-unicode/2.1/courier-unicode-2.1.tar.bz2
# ls -l
合計 440
-rw-r--r-- 1 root root 447917 9月 18 2018 courier-unicode-2.1.tar.bz2

 

▼rpmbuild実行
先ほどの「courier-authlibのRPM化」の手順のように依存関係で必要なパッケージが大量に要求された場合は、必要なパッケージのインストール後に再度rpmbuildを実行します。
依存関係のあるパッケージのインストール方法例については、後に開設する CourierMailServerで必要なパッケージのインストール方法 の手順を参照。

 command
# rpmbuild -tb courier-unicode-2.1.tar.bz2

 

▼書き出されたRPMファイルの確認
rpmbuild実行後は、実行ユーザーの /home/username/rpmbuild にパッケージが書き出されます。

 command
# cd ~/rpmbuild/RPMS/x86_64/
# ls -lrt | grep unicode
-rw-r--r-- 1 root root 69640 10月 3 16:18 courier-unicode-2.1-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 112212 10月 3 16:18 courier-unicode-devel-2.1-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 79244 10月 3 16:18 courier-unicode-debugsource-2.1-1.el8.x86_64.rpm
-rw-r--r-- 1 root root 147696 10月 3 16:18 courier-unicode-debuginfo-2.1-1.el8.x86_64.rpm

いくつかファイルが書き出されますが必要なパッケージは下記の2つです。

  • courier-unicode-2.1-1.el8.x86_64.rpm
  • courier-unicode-devel-2.1-1.el8.x86_64.rpm

 

▼必要なRPMファイルのインストール
下記2つのライブラリのみインストール。
rpmコマンドの使い方は こちら を参照。

 command
# rpm -ivh courier-unicode-2.1-1.el8.x86_64.rpm
# rpm -ivh courier-unicode-devel-2.1-1.el8.x86_64.rpm

 

 

CourierMailServerのインストール

▼CourierMailServerのDL
DL後にrpmbuild実行しますが、先ほどのunicodeとauthlibとは違い一般ユーザーで実行する必要があります。
下記の場合rootでファイルをDLしているので、実行する一般ユーザーのオーナー権限に変更しておきます。

 command
# wget https://sourceforge.net/projects/courier/files/courier/1.0.14/courier-1.0.14.tar.bz2
# chown username.username courier-1.0.14.tar.bz2
# ls -l
-rw-r--r-- 1 username username 7541652 6月 18 10:32 courier-1.0.14.tar.bz2

 

▼一般ユーザーに変更
先ほどCourierMailServerをDLしたディレクトリに移動します。

 command
# su - username
# cd /home/username/tmp/

 

▼courier-1.0.14.tar.bz2をRPM化
下記のようにオプション「--with-notice=unicode」を指定してbuildしないと、ビルド中に自動で行われるソースコードを元に行われる環境作成とチェック(./configure)でエラーになります。
rpmbuild実行後は、一般ユーザーの「/home/username/rpmbuild」にパッケージが書き出されます。

 command
$ rpmbuild -tb --define 'notice_option --with-notice=unicode' courier-1.0.14.tar.bz2
エラー: ビルド依存性の失敗:
/usr/bin/certtool は courier-1.0.14-1.el8.x86_64 に必要とされています
/usr/include/fam.h は courier-1.0.14-1.el8.x86_64 に必要とされています
/usr/lib/locale/locale-archive は courier-1.0.14-1.el8.x86_64 に必要とされています
courier-authlib-devel >= 0.55 は courier-1.0.14-1.el8.x86_64 に必要とされています
courier-unicode-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
expect は courier-1.0.14-1.el8.x86_64 に必要とされています
gcc-c++ は courier-1.0.14-1.el8.x86_64 に必要とされています
gdbm-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
ghostscript は courier-1.0.14-1.el8.x86_64 に必要とされています
gnutls-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
groff は courier-1.0.14-1.el8.x86_64 に必要とされています
libgcrypt-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
libidn-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
make は courier-1.0.14-1.el8.x86_64 に必要とされています
mgetty-sendfax は courier-1.0.14-1.el8.x86_64 に必要とされています
netpbm-progs は courier-1.0.14-1.el8.x86_64 に必要とされています
pam-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
pcre-devel は courier-1.0.14-1.el8.x86_64 に必要とされています
perl は courier-1.0.14-1.el8.x86_64 に必要とされています
perl(ExtUtils::Embed) は courier-1.0.14-1.el8.x86_64 に必要とされています
perl-generators は courier-1.0.14-1.el8.x86_64 に必要とされています

上記は courier-authlib をインストールする前に実行した結果のため、エラー量が多い状況です。
今回の例を依存関係のあるパッケージのインストール方法を解説します。
依存関係のあるコマンド等は何のパッケージを入れると良いか、概ね下記でパッケージ名を入力することで調べることも出来ます。
http://rpmfind.net/linux/RPM/index.html

 

▼開発ツール関連があるリポジトリの有効化

 command
# vi /etc/yum.repos.d/CentOS-PowerTools.repo
「enabled=0」を「enabled=1」に変更して有効化

 

CourierMailServerで必要なパッケージのインストール方法

▼インストールするにあたり
基本的はdnfコマンドにてRPMパッケージでコマンドやライブラリ等がインストールできますが、無いものはネット上で公開されているパッケージ等を探してインストールする必要があります。

CentOS 8 では dnf コマンドを利用してパッケージ情報検索やインストール、削除を行うことができます。
パッケージファイルが管理されているダウンロードサーバーをリポジトリと呼び、新規でリポジトリを追加することで、ダウンロードできるファイルの種類を増やすことが可能です。


「-y」オプションを指定すると、インストール可否の確認で「yes」となり自動的にインストールが開始します。

 

▼「certtool」コマンドのインストール
秘密鍵や証明書を作成するのに使われるコマンドで、「gnutls-utils」パッケージをインストール

 command
# dnf -y install gnutls-utils
# which certtool
/usr/bin/certtool

 

▼「/usr/include/fam.h」は「gamin-devel」をインストール

 command
# dnf -y install gamin-devel
# ls /usr/include/fam.h
/usr/include/fam.h

 

▼「/usr/lib/locale/locale-archive」は「glibc-all-langpacks」をインストール

 command
# dnf -y install glibc-all-langpacks
# ls /usr/lib/locale/locale-archive
/usr/lib/locale/locale-archive

 

▼expectのインストール
「expect」は「courier-authlib」をインストール時に自動でインストールされるので割愛。

 

▼gcc-c++のインストール
c++で作成されたソースをコンパイルするためのコンパイラです。

 command
# dnf -y install gcc-c++

 

▼gdbm-develのインストール
GNU データベースシステムである gdbm 用の開発ライブラリです。

 command
# dnf -y install gdbm-devel

 

▼ghostscriptのインストール
アドビ社の開発したページ記述言語「PostScript」を提供するライブラリ。
Linuxで印刷等を行う場合はPostScript形式で扱う。

 command
# dnf -y install ghostscript

 

▼gnutls-develのインストール
SSL/TLSとDTLSプロトコルの開発ライブラリ。

 command
# dnf -y install gnutls-devel

 

▼groffのインストール
GNU プロジェクトによる文章成型コマンドroffの代替えとなるコマンド。

 command
# dnf -y install groff

 

▼libgcrypt-develのインストール
汎用的な暗号化ライブラリ。

 command
# dnf -y install libgcrypt-devel

 

▼libidn-develのインストール
国際ドメインをエンコード、デコードするためのlibidnの開発ライブラリ。
日本語ドメイン名とかでアクセスできるようにしたりするのに使用されている技術です。

 command
# dnf -y install libidn-devel

 

▼makeのインストール
どのソースコードをどのようにコンパイルすれば良いかを判断して必要な処理を実行してくれるコマンド。

 command
# dnf -y install make.x86_64

 

▼netpbm-progsのインストール
画像などのグラフィックファイルを操作するためのライブラリ。

 command
# dnf list | grep netpbm-progs

 

▼pam-develのインストール
ユーザー認証モジュール(pam)の開発に必要なライブラリ

 command
# dnf list | grep pam-devel

 

▼pcre-develのインストール
perl互換の正規表現ライブラリ。

 command
# dnf -y install pcre-devel

 

▼perlのインストール
WEBアプリケーションの開発などに使われるプログラム言語。
表示されていた「perl(ExtUtils::Embed)」も同時にインストールされます。

 command
# dnf -y install perl

 

▼perl-generatorsのインストール
rpm-buildで必要なPerl依存関係ジェネレーター。

 command
# dnf -y install perl-generators

 

▼「mgetty-sendfax」のインストール
FAXサービスを提供可能なライブラリですが、CentOS8ではdnfで入手が出来ないため、CentOS7のパッケージを依存関係無視でインストールします。
「--nodeps」オプションで依存関係のパッケージをスキップさせます。
CourierMailServer のrpm化実行時にmgetty-sendfax のファイルさえ確認できれば依存関係のエラーは解消されます。
sendfax を用いたFAXサーバーを構築するのは限定的な条件だと思われるため、一般的なメールサーバーの構築では、sendfaxは動作しなくても影響はありません。

 command
# rpm -ivh --nodeps http://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/m/mgetty-sendfax-1.2.1-11.fc34.x86_64.rpm
# rpm -qa | grep mgetty-sendfax
mgetty-sendfax-1.2.1-10.fc33.x86_64

尚、上記 rpm コマンド実行時のURLが404となる場合は、こちら より最新版のファイル名に置き換えてください。

 

▼再度rpmbuildを実行

 command
$ rpmbuild -tb --define 'notice_option --with-notice=unicode' courier-1.0.14.tar.bz2

 

▼パッケージの書き出し場所

 command
$ cd /home/user1/rpmbuild/RPMS/x86_64
$ ls -lrt
合計 11140
-rw-rw-r-- 1 user1 user1 1150696 10月 2 15:42 courier-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 29936 10月 2 15:42 courier-ldap-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 8980 10月 2 15:42 courier-mysql-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 8984 10月 2 15:42 courier-pgsql-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 63168 10月 2 15:42 courier-pop3d-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 188400 10月 2 15:42 courier-imapd-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 410928 10月 2 15:42 courier-webmail-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 10628 10月 2 15:42 courier-webadmin-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 182980 10月 2 15:42 courier-mlm-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 150144 10月 2 15:42 courier-mlm-web-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 174096 10月 2 15:42 courier-maildrop-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 13940 10月 2 15:42 courier-fax-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 7728 10月 2 15:42 courier-maildrop-wrapper-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 877396 10月 2 15:42 courier-debugsource-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 3540012 10月 2 15:42 courier-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 42780 10月 2 15:42 courier-ldap-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 125468 10月 2 15:42 courier-pop3d-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 449868 10月 2 15:42 courier-imapd-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 899540 10月 2 15:42 courier-webmail-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 12248 10月 2 15:42 courier-webadmin-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 1501948 10月 2 15:42 courier-mlm-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 1074812 10月 2 15:42 courier-mlm-web-debuginfo-1.0.14-1.el8.x86_64.rpm
-rw-rw-r-- 1 user1 user1 442332 10月 2 15:42 courier-maildrop-debuginfo-1.0.14-1.el8.x86_64.rpm

 

▼rootユーザーに変更してRPMS配下に移動
先ほどrpmbuildを実行したユーザーのディレクトリに移動します。

 command
$ su -
# cd /home/username/rpmbuild/RPMS/x86_64/

 

▼perl-CGIをインストール
RPMパッケージをインストールする際に依存関係で必要になります。

 command
# dnf -y install perl-CGI

 

CourierMailServerのパッケージ説明とインストール

本ブログの手順でもまだ使われていないパッケージもありますが、使う可能性があるものはインストールしておきます。

 

▼courierコアパッケージのインストール

 command
#rpm -ivh courier-1.0.14-1.el8.x86_64.rpm

 

▼POPサーバーのインストール(受信用)

 command
#rpm -ivh courier-pop3d-1.0.14-1.el8.x86_64.rpm

 

▼IMAP4サーバーのインストール(受信メールのサーバー保存)

 command
#rpm -ivh courier-imapd-1.0.14-1.el8.x86_64.rpm

 

▼WEBメールのインストール

 command
#rpm -ivh courier-webmail-1.0.14-1.el8.x86_64.rpm

 

▼メールフィルタリング

 command
#rpm -ivh courier-maildrop-1.0.14-1.el8.x86_64.rpm
#rpm -ivh courier-maildrop-wrapper-1.0.14-1.el8.x86_64.rpm

 

▼ウェブベースの管理フロントエンド

 command
#rpm -ivh courier-webadmin-1.0.14-1.el8.x86_64.rpm

 

▼メーリングリスト

 command
#rpm -ivh courier-mlm-1.0.14-1.el8.x86_64.rpm
#rpm -ivh courier-mlm-web-1.0.14-1.el8.x86_64.rpm

 

▼MySQL連携

 command
#rpm -ivh courier-mysql-1.0.14-1.el8.x86_64.rpm

 

 

▼本手順で使用しないパッケージ

courier-fax-1.0.14-1.el8.x86_64.rpm FAXサーバー連動用のパッケージファイル
courier-ldap-1.0.14-1.el8.x86_64.rpm LDAP認証連動用のパッケージファイル
courier-pgsql-1.0.14-1.el8.x86_64.rpm PostgreSQLのDBサーバー連動用のパッケージファイル

 

 

コンフィグの設定

設定ファイルは/etc/courier以下に展開されます。
基本的にコンフィグファイルはデフォルトで作成されていないので新規でファイルを作成する必要があります。

一部の設定は、コンフィグファイルの修正後に反映コマンドを実行してサーバーに反映させることで、サーバーの再起動をしなくても即時反映されます。

 

コマンドで反映可能な設定
コンフィグ 用途 反映コマンド
smtpaccess SMTPリレー制御 makesmtpaccess
aliases アカウントの定義 makealiases
locals ローカル配信ドメインの設定
(メールアドレスが「aaaa@domain.com」の場合、ログインIDは「aaaa」で検索される。)
makealiases
esmtpacceptmailfor.dir 受信ドメイン設定 makeacceptmailfor
hosteddomains バーチャルドメイン設定
(メールアドレスが「aaaa@domain.com」の場合、ログインIDは「aaaa@domain.com」で検索される。)
makehosteddomains

▼postmasterの設定
root や postmaster, MAILER-DAEMON などに宛てたメールを受け取るメールアカウントを設定する必要があります。
Courier は root ユーザーにはいかなるメールも配信しないので、一般ユーザーのアカウントを指定する必要があります。

 command
# vi /etc/courier/aliases/system

system

postmaster:

postmaster: username

 

▼defaultdomainファイルを新規作成

 command
# vi /etc/courier/defaultdomain

defaultdomain

example.com

 

▼webadminファイルを新規作成

 command
# vi /etc/courier/esmtpacceptmailfor.dir/webadmin

webadmin

example.com

 

▼esmtpdの変更

 command
# vi /etc/courier/esmtpd

esmtpd

ESMTPDSTART=NO

ESMTPDSTART=YES

 

▼ローカルで受けるドメインの設定を新規作成

 command
# vi /etc/courier/locals

locals

example.com

・メールアドレスが「aaaa@example.com」の場合、ログインIDは「aaaa」で検索されます。
・ログインIDが「aaaa@example.com」のようにドメインも含めたい場合は、localsは空欄で「hosteddomains」にドメインを記述します。
両方記述した場合は、localsが優先で読まれます。

 

▼自ホスト名の設定を新規作成

 command
# vi /etc/courier/me

me

example.com     または
mail.example.com     など

 

▼courierのアクセスポリシーを修正

 command
# vi /etc/courier/smtpaccess/default

default

127.0.0.1 allow,RELAYCLIENT
xxx.xxx.xxx.xxx allow,RELAYCLIENT :この行に自サーバーの固定IPを記述
192.168 allow,RELAYCLIENT

上記以外はコメントアウト(#)する。

 

▼WEB管理画面のパスワード
設定ファイルを全てviで修正するなら管理画面は使わないのですが一応設定しておきます。

 command
# vi /etc/courier/webadmin/password

password

hogehoge

 

▼SMTP認証の設定

 command
# vi /etc/courier/esmtpd

メモ

ESMTPAUTH=""

ESMTPAUTH="LOGIN PLAIN"

 

▼バーチャルドメインの設定
example.com以外のドメインを利用したメールサーバーを構築する場合は、下記のファイルを作成して記載してください。

 command
# vi /etc/courier/esmtpacceptmailfor.dir/default

default

▼メール転送を許可するドメイン
other-domain.com

 command
# vi /etc/courier/hosteddomains

hosteddomains

▼Courierが保有するドメイン一覧
other-domain.com

・ログインIDが「aaaa@other-domain.com」のようにドメインを含めたメールアドレス形式で検索されます。
・ログインIDにドメインを含まず「aaaa」で検索されるようにする場合は、「locals」にドメインを記述してください。

 

▼下記ディレクトリのコマンドPATHを設定
下記にsbin配下にcourierのコマンドが格納されていますので環境変数でPATHを通しておきます。

 command
# vi ~/.bash_profile
PATH=$PATH:/usr/lib/courier/sbin/

 

▼PATHの有効化
するために「-」をつけて環境変数を読み込みsuで再ログイン

 command
# su -

 

▼コマンドをwhichで検索すると表示される

 command
# which makehosteddomains
/usr/lib/courier/sbin/makehosteddomains

 

▼フォルダーのパーミッションを変更

 command
# chown daemon.daemon /etc/courier/ldapaliasrc

 

▼上記コンフィグの有効化

 command
# makehosteddomains
# makeacceptmailfor
# makealiases
# makesmtpaccess
# makesmtpaccess-msa

 

 

courierの自動起動設定

 command
# systemctl enable courier
Created symlink /etc/systemd/system/mail-transfer-agent.target.wants/courier.service → /usr/lib/systemd/system/courier.service.
Created symlink /etc/systemd/system/multi-user.target.wants/courier.service → /usr/lib/systemd/system/courier.service.
 
# systemctl is-enabled courier
enabled

enabled になっていればサーバー再起動で自動で敵にサービスが起動します。

 

▼courierのサービス起動

 command
# systemctl start courier

 

▼courierの起動確認

 command
# systemctl status courier
● courier.service - Courier Mail Server
Loaded: loaded (/usr/lib/systemd/system/courier.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-10-02 17:58:53 +03; 29min ago
:
:

最後までエラーが無く Active: active (running) となっていればOK。

 

▼courier認証デーモンの自動起動

 command
# systemctl enable courier-authlib
# systemctl is-enabled courier-authlib
enabled

enabled になっていればサーバー再起動で自動で敵にサービスが起動します。

 

▼courier認証デーモンの起動

 command
# systemctl start courier-authlib

 

▼courier認証デーモンの起動確認

 command
# systemctl status courier-authlib
● courier-authdaemon.service - Courier Authentication Daemon
Loaded: loaded (/usr/lib/systemd/system/courier-authdaemon.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-10-03 08:28:55 +03; 8s ago
:
:

最後までエラーが無く Active: active (running) となっていればOK。

 

 

メールを利用するCentOS側のユーザーを作成

▼ユーザーを作成

 command
# useradd testusr

 

▼ユーザー testusr のパスワードを変更

 command
# passwd testusr
新しいパスワード: ********
新しいパスワードを再入力してください: ********
passwd: すべての認証トークンが正しく更新できました。

▼Maildir確認
ユーザー作成後にメールが格納されるMaildirが作成されているので確認をします。

 command
# ls -lrt /home/testusr/
合計 0
drwx------ 5 testusr testusr 39 10月 2 16:13 Maildir

 

 

メール認証アカウントの作成

▼アカウント情報に必要なuidとpidを確認
下記の例では「testusr」ユーザー名のGIDとUIDが「1009」というのを確認。

 command
# cat /etc/passwd | grep testusr
testusr:x:1009:1009::/home/testusr:/bin/bash

 

▼ユーザーdbファイルの作成
(courierのホストと同じドメインのアドレスの場合)

 command
# userdb testusr set uid=1009 gid=1009 home=/home/testusr
# userdbpw -md5 | userdb testusr set systempw
Password:
Reenter password:

 

▼ユーザーdbファイルの作成
(courierのホストと違うバーチャルドメインの場合)
ユーザー名の後にドメインを記載します。
この場合はメーラーに設定するユーザー名も「testusr@other-domain.com」とドメインの記載されたユーザー名になります。

 command
# userdb testother@other-domain.com set uid=1001 gid=1001 home=/home/testother
# userdbpw -md5 | userdb testother@other-domain.com set systempw
Password:
Reenter password:

 

▼作成されたユーザーデータのファイル確認

 command
cat /etc/authlib/userdb
cat userdb
testusr systempw=$1$Vfdmqf4H$u78T6H2IlFTPif/F3Lej71|uid=1009|gid=1009|home=/home/testusr
testother@other-domain.com systempw=$1$.cb.LhH1$ksJX5CIROyrBR4BDkPLE11|uid=505|gid=505|home=/home/testother

 

▼courier-authlibに反映
初回目実行時に上記「/etc/authlib/userdb」ファイルが作成されます。
下記コマンドを実行すると userdb ファイルの記述内容を元にバイナリデータが同一ディレクトリに作成されます。
実際の認証に使われるデータは、このバイナリファイルが利用されます。

 command
# makeuserdb

 

 

メーラーでアカウントを設定してログイン確認

▼上記設定例でのログイン

メールアドレス testusr@example.com
受信メール imap4 or pop3 ※本手順ではではimap4想定
ユーザー(#courierのホスト名と同一) testusr
ユーザー(バーチャルドメインを利用) testother@other-domain.com
パスワード userdbpw実行時に入力したパスワード
SMPTポート(メール送信用) 587
POP3ポート(メール受信用 ※DL型 110
IMAP4ポート(メール受信用 ※サーバー側で管理 143
認証方法 SMTP認証 LOGIN

 

▼ログインエラー等になった場合のログの確認方法
tail -f でリアルタイムにログを表示。

 command
# tail -f /var/log/maillog

ログ表示を止める場合は「Ctrl+C」

 

▼デバッグモードにしてmaillogを確認
デバッグモードにするとログインセッションの細かい応答内容等が分かるようになり、ログインエラー発生時の解析が可能です。
ログの量が多くファイルサイズが肥大化するため、解析が完了したらデバッグモードを無効化してください。

 command
# /etc/authlib/authdaemonrc
DEBUG_LOGIN=0
↓
DEBUG_LOGIN=1 #フラグを1にしてデバッグモードを起動。

 

▼authlibを再起動でデバッグモードの設定を反映

 command
# systemctl restart courier-authlib

 

 

おすすめ

1

目次1 Windows10で構築するサーバー構成の例2 Windows10 記憶域について3 Windows10 Hyper-vについて Windows10で構築するサーバー構成の例 知らない人も多い ...

2

目次1 記憶域について2 記憶域の作成方法 記憶域について この記事ではWindows 10 の記憶域によるストレージの作成方法について解説します。 そもそも記憶域について詳しく知りたい方は、下記の記 ...

3

目次1 概要2 テキストパーツ3 ボックスデザイン4 カスタムボタン5 会話ふきだし6 ランキング7 レイアウト8 その他パーツ9 記事一覧/カード10 ショートコード補助11 AFFINGER5につ ...

4

ディレクションを担当した世界遺産のガイドアプリより、ムービー用のBGMを1曲担当しました。 Misumi-nishikou It is BGM created for app video. sound ...

5

こちらはプライベートで作成したYoutube投稿用サイクリングムービーのBGMです。 EDM Sound-2 EDM sound for my Youtube. soundcloud.com

-MAIL (Courier-MTA), Server