メールサーバの構築
インストール
Postfix、Dovecot、cyrus-saslをまずインストールする。
dnf install postfix dovecot cyrus-sasl
Postfixの設定
設定ファイルmain.cfを開く。
vi /etc/postfix/main.cf
以下のように編集する。
# 自FQDN名を指定
myhostname = mail.server.net
# 自ドメイン名を指定
mydomain = server.net
# ローカルからのメール送信時の送信元メールアドレス@以降にドメイン名を付加
myorigin = $mydomain
# 外部からのメール受信を許可
inet_interfaces = all
# 自ドメイン宛メールを受信できるようにする
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# UNIXアカウントかエイリアスに登録されているユーザー以外の宛先のメールを拒否する
local_recipient_maps = unix:passwd.byname $alias_maps
# メールボックス形式をMaildir形式にする
home_mailbox = Maildir/
# メールサーバーソフト名の隠蔽化
smtpd_banner = $myhostname ESMTP unknown
# 以下を追加。SMTP-Auth設定
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
smtpd_sasl_type = dovecot
# 受信サイズを10MB=10*1024*1024に制限
message_size_limit = 10485760
設定ファイルmaster.cfを開く。
vi /etc/postfix/master.cf
以下のように編集する。
# 以下のコメントを外す
submission inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
saslauthdを起動する。
systemctl start saslauthd
saslauthdが自動起動するように設定する。
systemctl enable saslauthd
もしsendmailが動いていれば、止める。
systemctl stop sendmail
sendmailの自動起動設定がしてあれば、止める。
systemctl disable sendmail
システムで使用するメールサーバ機能をsendmailからpostfixに切り替える。
表示されるリストのうち、コマンドが「/usr/sbin/sendmail.postfix」になっているものを選択する。
alternatives --config mta
2 プログラムがあり 'mta' を提供します。
選択 コマンド
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.postfix
2 /usr/sbin/sendmail.sendmail
Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:1
新規ユーザーアカウント作成時にMaildirディレクトリが自動的に作成されるようにする。
mkdir /etc/skel/Maildir
mkdir /etc/skel/Maildir/cur
mkdir /etc/skel/Maildir/new
mkdir /etc/skel/Maildir/tmp
chmod 700 -R /etc/skel/Maildir
既存ユーザーには、Maildirディレクトリを作成する。
cd /home/[user]/
mkdir Maildir
mkdir Maildir/cur
mkdir Maildir/new
mkdir Maildir/tmp
chmod 700 -R Maildir
chown [user]. -R Maildir
Postfixを再起動する。
systemctl restart postfix
Postfixが自動起動するように設定する。
systemctl enable postfix
Dovecotの設定
設定ファイルdovecot.confを開く。
vi /etc/dovecot/dovecot.conf
以下のように編集する。
protocols = imap lmtp
listen = *, ::
設定ファイル10-mail.confを開く。
vi /etc/dovecot/conf.d/10-mail.conf
以下のように編集する。
# メールボックス形式をMaildir形式とする
mail_location = maildir:~/Maildir
設定ファイル10-auth.confを開く。
vi /etc/dovecot/conf.d/10-auth.conf
以下のように編集する。
# プレインテキスト認証を許可
disable_plaintext_auth = no
設定ファイル10-master.confを開く。
vi /etc/dovecot/conf.d/10-master.conf
以下のように編集する。
service imap-login {
inet_listener imap {
port = 143
}
}
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
Dovecotを起動する。
systemctl start dovecot
Dovecotが自動起動するように設定する。
systemctl enable dovecot
ポート開放
143/tcpと587/tcpのポートを開ける必要がある。
firewall-cmd --add-service=imap --permanent
firewall-cmd --add-service=smtp --permanent
firewall-cmd --add-service=smtp-submission --permanent
firewall-cmd --reload