local imapサーバーを立てた

投稿日:

iijmioのセーフティメールはimap4に対応しておらず、複数のPCでメールを管理するのに不便なので、fetchmailでとってきたメールをimapサーバー上で管理するようにしてみた。

imapサーバーにdovecotを使うことににした。

以下、設定メモ。

dovecotの設定

pkgからインストール。sieveも使いたいのでpigeonholeもインストール。

# pkg install dovecot dovecot-pigeonhole

設定はとりあえずこれだけ。pop3無効化、SSL有効化、sieve有効化。あと、同時コネクション数を多めに設定。

diff -uNr example-config/dovecot.conf dovecot.conf
--- example-config/dovecot.conf 2018-02-03 10:16:02.000000000 +0900
+++ dovecot.conf 2018-02-20 09:47:40.732035000 +0900
@@ -22,12 +22,14 @@
 
 # Protocols we want to be serving.
 #protocols = imap pop3 lmtp
+protocols = imap lmtp
 
 # A comma separated list of IPs or hosts where to listen in for connections. 
 # "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
 # If you want to specify non-default ports or anything more complex,
 # edit conf.d/master.conf.
 #listen = *, ::
+listen = *, ::
 
 # Base directory where to store runtime data.
 #base_dir = /var/run/dovecot/
diff -uNr example-config/conf.d/10-auth.conf conf.d/10-auth.conf
--- example-config/conf.d/10-ssl.conf 2018-02-03 10:16:02.000000000 +0900
+++ conf.d/10-ssl.conf 2018-02-20 13:44:51.515706000 +0900
@@ -4,13 +4,16 @@
 
 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
 #ssl = yes
+ssl = required
 
 # PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
 # dropping root privileges, so keep the key file unreadable by anyone but
 # root. Included doc/mkcert.sh can be used to easily generate self-signed
 # certificate, just make sure to update the domains in dovecot-openssl.cnf
-ssl_cert = </etc/ssl/certs/dovecot.pem
-ssl_key = </etc/ssl/private/dovecot.pem
+ssl_cert = </usr/local/etc/letsencrypt/live/xxx/fullchain.pem
+ssl_key = </usr/local/etc/letsencrypt/live/xxx/privkey.pem
 
 # If key file is password protected, give the password here. Alternatively
 # give it when starting dovecot with -p parameter. Since this file is often
diff -uNr example-config/conf.d/15-lda.conf conf.d/15-lda.conf
--- example-config/conf.d/15-lda.conf 2018-02-03 10:16:02.000000000 +0900
+++ conf.d/15-lda.conf 2018-02-20 13:48:32.655705000 +0900
@@ -45,4 +45,5 @@
 protocol lda {
 # Space separated list of plugins to load (default is global mail_plugins).
 #mail_plugins = $mail_plugins
+ mail_plugins = $mail_plugins sieve
 }
diff -uNr example-config/conf.d/20-imap.conf conf.d/20-imap.conf
--- example-config/conf.d/20-imap.conf 2018-02-03 10:16:02.000000000 +0900
+++ conf.d/20-imap.conf 2018-02-20 10:19:09.307693000 +0900
@@ -89,4 +89,5 @@
 # Maximum number of IMAP connections allowed for a user from each IP address.
 # NOTE: The username is compared case-sensitively.
 #mail_max_userip_connections = 10
+ mail_max_userip_connections = 100
 }
diff -uNr example-config/conf.d/20-lmtp.conf conf.d/20-lmtp.conf
--- example-config/conf.d/20-lmtp.conf 2018-02-03 10:16:02.000000000 +0900
+++ conf.d/20-lmtp.conf 2018-02-20 13:50:58.133168000 +0900
@@ -23,4 +23,5 @@
 protocol lmtp {
 # Space separated list of plugins to load (default is global mail_plugins).
 #mail_plugins = $mail_plugins
+ mail_plugins = $mail_plugins sieve
 }

rc.confに自動起動設定を追加

#dovecot
dovecot_enable="YES"

fetchmail

fetchmailもパッケージから

# pkg install fetchmail

~/.fetchmailrcにpop3サーバーの設定を書いて、自動起動の設定をする。

set postmaster root
set no bouncemail

defaults
    protocol POP3
    uidl
    keep
    ssl
    no mimedecode
    mda "/usr/local/libexec/dovecot/deliver"

poll mbox.iijmio-mail.jp
    user "USER"
    password "PASSWORD"

/etc/rc.confにはfetchmail_usersを設定し、ユーザーごとのデーモンを立ち上げる設定にする。(fetchmail_userとfetchmail_usersがあって紛らわしいので間違わないようにする。というか、間違えた。)

#fetchmail
fetchmail_enable="YES"
fetchmail_polling_interval="600"
fetchmail_users="ueda"

サービス開始

以下のコマンドでサービスを開始し、Androidのメールチェックプラスというアプリでメールが見えるところまで確認。

# service dovecot start
# service fetchmail start

PCのクライアントにはsieveの設定ができるといわれているThunderbirdを使おうかと。
また追々。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です