LoginSignup
3
7

More than 5 years have passed since last update.

Postfix + dovecot + RainloopでメールサーバとWebクライアント作成(CentOS7.4)

Last updated at Posted at 2017-09-17

表題通りです。いろんなサービスが存在しますが、独自構築したいと思います。

構築部分はこちらを参考にさせていただきました。
https://centossrv.com/postfix.shtml
http://qiita.com/shadowhat/items/2872104e40dd219edb13

目指したい事

さくらVPSを基盤にメールサーバ構築、同ホスト上にRainloopを構築してブラウザ上からWebクライアントを利用する。メールサーバはpamの認証を利用して、linuxのユーザ、パスワードをメール関連(smtp/imap)の認証にも使い回したい。また、このメールサーバからリレーなど転送しない。

必要なソフトウェア
CentOS7.4
Postfix
cyrus-sasl
dovecot
Rainloop
(apache+php含む)

Postfixの導入と設定

さくらVPSにはインストール済みでした

$ postconf  | grep mail_version
$ mail_version = 2.10.1
$ milter_macro_v = $mail_name $mail_version

設定変更

/etc/postfix/main.cf
変更
inet_interfaces = 127.0.0.1
→inet_interfaces = all

追記
myhostname = kusakari.style
mydomain = kusakari.style
myorigin = $mydomain
home_mailbox = Maildir/
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_unauth_destination
message_size_limit = 10485760

自動起動の設定とポート開放

$ firewall-cmd --add-port=587/tcp --zone=public --permanent
$ firewall-cmd --reload
$ systemctl start postfix
$ systemctl enable postfix
$ systemctl list-unit-files  | grep post
postfix.service enabled 

cyrus-saslの導入と設定

SMTPの認証にはcyrus-saslを利用します

$ yum install cyrus-sasl
$ systemctl start saslauthd
$ systemctl enable saslauthd
$ systemctl list-unit-files  | grep sasl
saslauthd.service enabled

dovecotの導入と設定

IMAPのみ利用します

$ yum install dovecot

設定ファイルの編集

/etc/dovecot/conf.d/10-mail.conf
追加
mail_location = maildir:~/Maildir
/etc/dovecot/conf.d/10-auth.conf
追加
disable_plaintext_auth = no
/etc/dovecot/conf.d/10-ssl.conf
追加
ssl = no

自動起動の設定とポート開放

$ firewall-cmd --add-port=143/tcp --zone=public --permanent
$ firewall-cmd --reload
$ systemctl start dovecot
$ systemctl enable dovecot
$ systemctl list-unit-files  | grep dovecot
dovecot.service enabled 

動くか確認する

$ telnet localhost imap
$ telnet localhost imap
1 login kusakari password
OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE BINARY MOVE] Logged in
1 logout

Rainloopの導入と設定

前回記事でWordPress導入時にも同じ事をやりましたが、一応記載します。

事前準備

$ yum install php
$ grep DocumentRoo /etc/httpd/conf/httpd.conf  
DocumentRoot "/var/www/html"
$ cd /var/www/html/
$ wget http://repository.rainloop.net/v2/webmail/rainloop-community-latest.zip
$ find . -type d -exec chmod 755 {} \;
$ find . -type f -exec chmod 644 {} \;

Apacheの設定追加

/etc/httpd/conf/httpd.conf
DirectoryIndex index.php
Alias /rainloop /var/www/html/rainloop

Apacheの再起動とポート開放

$ firewall-cmd --add-port=80/tcp --zone=public --permanent
$ firewall-cmd --reload
$ /sbin/apachectl configtest
Syntax OK
$ systemctl start httpd
$ systemctl enable httpd
$ systemctl list-unit-files  | grep httpd

画面で確認
http://<ホスト名>/

拡張が足りないので、追加

[302] The following PHP extensions are not available in your PHP configuration!dom
$ yum install php-xml

権限が足りないので追加

[202] Data folder permissions error [is_writable]
$ cd /var/www/html/
$ chown -R apache:apache ./

それっぽい画面が表示されたので、設定画面に行きます。
http://160.16.215.246/?/admin
admin/12345でログインできます

ここから先はGUIの設定になります。画面に沿って入力していくので、今回はここで打ち切ります。後日追記するかもしれません。メールを受信できるようになったら次はメールを通知する仕組みに進み、LINE Notifyなど便利な仕組みが多数あるので後日まとめたいと思います。

3
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
7