postfix/dovecotでローカル専用メールサーバを構築
参考サイトは以下。
http://d.hatena.ne.jp/uriyuri/20080704/1215163436
http://ngyuki.hatenablog.com/entry/20110725/p1
http://www.postfix-jp.info/trans-2.2/jhtml/postconf.5.html
postfixの設定
# alternatives --display mta postfixがデフォルトになっていることを確認。postfix自体がない場合は、yumでインストール。 sendmailがデフォルトのMTAになっている場合は、alternatives --config mta にて変更する必要あり。 # yum install -y postfix .... # cd /etc/postfix # cp -ip main.cf main.cf.org # vi main.cf inet_interfaces = all mynetworks = 172.16.167.0/24 home_mailbox = Maildir/ luser_relay = root transport_maps = hash:/etc/postfix/transport # cp -ip transport transport.org # vi transport localhost : * local: # postmap /etc/postfix/transport # /etc/rc.d/init.d/postfix reload
ローカルにて送信のテスト
telnetで確認してみる。telnetがインストールされていない場合はtelnetでインストールする。
# yum install telnet .... # telnet localhost smtp Trying ::1... Connected to localhost. Escape character is '^]'. 220 localhost.localdomain ESMTP Postfix helo localhost.localdomain (入力値) 250 localhost.localdomain mail from:kohchi@localhost.localdomain (入力値) 250 2.1.0 Ok rcpt to:kohchi@localhost.localdomain (入力値。@以降省略可能) 250 2.1.5 Ok data (入力値) 354 End data with <CR><LF>.<CR><LF> Subject: test (以下、"."まで入力値) To: kohchi@localhost.localdomain This is test by telnet . 250 2.0.0 Ok: queued as 330F340353 quit (入力値) 221 2.0.0 Bye Connection closed by foreign host.
dovecotの設定
メール受信サーバとしてdovecotをインストールする。CentOS6.3のdovecotは2.0なのでprotocolsにimapsやpop3sは記述しなくてもよいみたい。
# yum install dovecot .... # cd /etc/dovecot # cp -ip dovecot.conf dovecot.conf.org # vi dovecot.conf protocols = imap pop3 # cd conf.d # cp -ip 10-mail.conf 10-mail.conf.org # vi 10-mail.conf mail_location = maildir:~/Maildir # cp -ip 10-master.conf 10-master.conf.org # vi 10-master.conf service imap-login { inet_listener imap { port = 143 } inet_listener imaps { port = 993 ssl = yes } } service pop3-login { inet_listener pop3 { port = 110 } inet_listener pop3s { port = 995 ssl = yes } } # chkconfig dovecot on # chkconfig --list dovecot dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off # service dovecot start
SELinuxを無効
メール受信の確認のため、pop3にてアクセスしてみたが、permissionのエラーが/var/log/maillogに吐かれて接続できない。
どうも、CentOS6.3をインストールする際にSELinuxを有効にした記憶はないのだが有効になっていたようなので無効にする。
# getenforce Enforcing # cd /etc/selinux # cp -ip config config.org # vi config SELINUX=disabled # enforcingになっていたのを変更 # sync;sync;sync # shutdown -rt 0 now ....
リブート後、SELinuxの確認を行い、pop3で確認してみる。
# getenforce Disabled # telnet localhost pop3 Trying ::1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user kohchi (入力値) +OK pass パスワード入力 +OK Logged in. list (入力値) +OK 2 messages: 1 547 2 504 . quit +OK Logging out. Connection closed by foreign host.