ここではLinuxアカウントがそのままメールアカウントになる運用方法を前提として記載してます。
この場合、POP/IMAPサーバへの接続はLinuxアカウントのパスワードになります。
*pam経由でPOP/IMAP認証を行ってます

POP/IMAPの導入

常にtelnetでメールを出すわけにはいかない。
PCから気軽にメールを出す、受け取るためにもPOP/IMAPサービスとして、ここではdovecotを採用します。
POPかIMAP。メールサーバのストレージに余裕があるのならIMAPかな。
IMAPだから、ではないが、postfixのメール格納方法を変更する

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
[root@c ~]# diff -u  /etc/postfix/main.cf.170316 /etc/postfix/main.cf
--- /etc/postfix/main.cf.170316 2017-03-15 20:40:39.283125125 +0900
+++ /etc/postfix/main.cf        2017-03-16 05:39:50.444328609 +0900
@@ -424,7 +424,7 @@
 # UNIX-style mailboxes are kept. The default setting depends on the
 # system type.
 #
-#mail_spool_directory = /var/mail
+mail_spool_directory = /var/mail/
 #mail_spool_directory = /var/spool/mail
 
 # The mailbox_command parameter specifies the optional external
[root@c ~]#

もし/var/mailに各ユーザのメールがあるのなら、、変換ツールでmailbox形式からmaildir形式に変換します。面倒なら削除..
そしてpostfixを再起動します。

その後に、dovecotをインストールします

[root@c ~]# yum install dovecot

そして、まずはメール保存先を指定します。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
[root@c ~]# diff -u /etc/dovecot/conf.d/10-mail.conf.orig /etc/dovecot/conf.d/10-mail.conf
--- /etc/dovecot/conf.d/10-mail.conf.orig       2017-03-16 06:00:50.081678104 +0900
+++ /etc/dovecot/conf.d/10-mail.conf    2017-03-16 06:01:27.659086030 +0900
@@ -27,7 +27,7 @@
 #
 # <doc/wiki/MailLocation.txt>
 #
-#mail_location =
+mail_location = maildir:/var/mail/%u
 
 # If you need to set multiple mailbox locations or want to change default
 # namespace settings, you can do it by defining namespace sections.
[root@c ~]#

mkdir /var/mail/<ユーザ> && chown uid:gid /var/mail/<ユーザ>
次に、POP/IMAPへの接続認証方法を定める SMTP認証ではありません

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
[root@c ~]# diff -u /etc/dovecot/conf.d/10-auth.conf.orig /etc/dovecot/conf.d/10-auth.conf
--- /etc/dovecot/conf.d/10-auth.conf.orig       2017-03-16 06:04:55.536812493 +0900
+++ /etc/dovecot/conf.d/10-auth.conf    2017-03-16 15:37:07.021131667 +0900
@@ -7,7 +7,7 @@
 # matches the local IP (ie. you're connecting from the same computer), the
 # connection is considered secure and plaintext authentication is allowed.
 # See also ssl=required setting.
-#disable_plaintext_auth = yes
+disable_plaintext_auth = no
 
 # Authentication cache size (e.g. 10M). 0 means it's disabled. Note that
 # bsdauth, PAM and vpopmail require cache_key to be set for caching to be used.
@@ -97,7 +97,7 @@
 #   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
 #   gss-spnego
 # NOTE: See also disable_plaintext_auth setting.
-auth_mechanisms = plain
+auth_mechanisms = plain login
 
 ##
 ## Password and user databases
[root@c ~]#
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
[root@c ~]# diff -u /etc/dovecot/conf.d/10-ssl.conf.orig /etc/dovecot/conf.d/10-ssl.conf
--- /etc/dovecot/conf.d/10-ssl.conf.orig        2017-03-16 15:23:03.528155922 +0900
+++ /etc/dovecot/conf.d/10-ssl.conf     2017-03-16 15:23:08.851073692 +0900
@@ -5,7 +5,7 @@
 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
 # disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
 # plain imap and pop3 are still allowed for local connections
-ssl = required
+ssl = no
 
 # 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@c ~]#

メールクライアントとの接続

2017y03m19d_190433046.png
上記は、内部のネットワークからアクセスを前提にしているので通信の暗号化などは行っていない。
ThunderbirdでのPOP/IMAP設定は
2017y03m19d_184159401.png
で行ける。FWでPOP(110),IMAP(143)は閉じているので内部だけ利用可能

SMTPは/etc/postfix/main.cfmynetworksの値が

[root@c ~]# postconf |grep ^mynetworks
mynetworks = 127.0.0.0/8 192.168.0.0/24 [::1]/128 [fe80::]/64
mynetworks_style = subnet
[root@c ~]#

なのでサブドメインに所属しているマシンはSMTP認証なしでローカルのSMTPマシンに投げれる。
そのためThunderbirdのSMTP設定部分は
2017y03m19d_191524818.png
で行ける

メールクライアントを外部で使いたい

メールの送信を外部から行いたい場合は、mail/smtp-authを参照
外部から接続する場合、メールクライアントとメールサーバ間の通信の暗号化くらいは行ったほうがいいみたい。
そのためには証明書が必要で、dovecotパッケージにはそのツールが用意されている

dovecot-openssl.cnfの内容を自サイトに合わせて調整して、mkcert.shを実行すれば証明書は作成される。

[root@c ~]# diff -u /etc/pki/dovecot/dovecot-openssl.cnf.orig /etc/pki/dovecot/dovecot-openssl.cnf
--- /etc/pki/dovecot/dovecot-openssl.cnf.orig   2013-03-14 22:28:31.000000000 +0900
+++ /etc/pki/dovecot/dovecot-openssl.cnf        2017-03-29 10:35:28.395391404 +0900
@@ -7,25 +7,25 @@
 
 [ req_dn ]
 # country (2 letter code)
-#C=FI
+C=JP
 
 # State or Province Name (full name)
-#ST=
+ST=Tokyo
 
 # Locality Name (eg. city)
-#L=Helsinki
+L=Chuo
 
 # Organization (eg. company)
-#O=Dovecot
+O=Chaperone
 
 # Organizational Unit Name (eg. section)
 OU=IMAP server
 
 # Common Name (*.example.com is also possible)
-CN=imap.example.com
+CN=web.chaperone.jp
 
 # E-mail contact
-emailAddress=postmaster@example.com
+emailAddress=postmaster@chaperone.jp
 
 [ cert_type ]
 nsCertType = server
[root@c ~]#

と修正して、mkcert.shを実行する

[root@c ~]# rm -rf /etc/pki/dovecot/certs/dovecot.pem    <-- dovecotパッケージに同封された証明書(imap.example.com向け)
[root@c ~]# rm -rf /etc/pki/dovecot/private/dovecot.pem  <-- dovecotパッケージに同封された秘密鍵
[root@c ~]# /usr/libexec/dovecot/mkcert.sh
Generating a 1024 bit RSA private key
.......++++++
.................................++++++
writing new private key to '/etc/pki/dovecot/private/dovecot.pem'
-----
 
subject= /C=JP/ST=Tokyo/L=Chuo/O=Chaperone/OU=IMAP server/CN=web.chaperone.jp/emailAddress=postmaster@chaperone.jp
SHA1 Fingerprint=36:7A:C6:00:5A:47:04:9D:A9:3B:2B:11:93:4D:52:37:86:D7:29:95
[root@c ~]#

これで、証明書(/etc/pki/dovecot/certs/dovecot.pem)と秘密鍵(/etc/pki/dovecot/private/dovecot.pem)が作成されました。
証明書の確認は

[root@c ~]# openssl x509 -in /etc/pki/dovecot/certs/dovecot.pem -text

にて可能です。
次に、/etc/dovecot/conf.d/10-ssl.confの内容を修正して、ssl通信を有効にさせ、dovecotを再起動します

[root@c ~]# diff -u /etc/dovecot/conf.d/10-ssl.conf.170329 /etc/dovecot/conf.d/10-ssl.conf
--- /etc/dovecot/conf.d/10-ssl.conf.170329      2017-03-29 10:51:30.433669406 +0900
+++ /etc/dovecot/conf.d/10-ssl.conf     2017-03-29 10:51:44.312457760 +0900
@@ -5,7 +5,7 @@
 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
 # disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
 # plain imap and pop3 are still allowed for local connections
-ssl = no
+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@c ~]#
[root@c ~]# systemctl restart dovecot

この後、ThunderbirdでのPOP/IMAP設定を下記のように設定しなおす。
2017y03m29d_110136110.png
これでアクセスしようとすると、下記警告が表示される。
2017y03m29d_110455549.png
例外を許諾すると、メールクライアントにこのメールサーバの証明書が登録される。
本来なら、正式な証明書を貰うべきかと思う。certbotを使うのも手なのかもしれない

この後、ルータを調整して外部からメールサーバへのアクセスを許可させる。
こちらではポートマッピングで993ポートをローカルメールサーバに結ばせている。

最新の60件
2026-05-09 2026-05-08 2026-05-06 2026-05-05 2026-05-04 2026-05-03 2026-05-02 2026-04-30 2026-04-29 2026-04-28 2026-04-27 2026-04-25 2026-04-24 2026-04-22 2026-04-21 2026-04-12 2026-04-08 2026-04-06 2026-04-05 2026-04-02 2026-03-26 2026-03-23 2026-03-21 2026-03-19 2026-03-15 2026-03-14 2026-03-13 2026-03-07 2026-03-06 2026-03-04 2026-03-02 2026-02-26 2026-02-24 2026-02-21 2026-02-18 2026-02-17 2026-02-16 2026-02-11 2026-02-09

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2017-03-30 (木) 19:39:29