独自ドメインを用いたメールサーバー構築(Postfix+Dovecot) – Raspberry Pi(ラズベリーパイ)

独自ドメインを用いたメールサーバー構築

1. postfix インストール

sudo apt-get install postfix
root@raspberrypi:/home/pi# sudo apt-get install postfix
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
提案パッケージ:
  procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin
  dovecot-common resolvconf postfix-cdb mail-reader ufw postfix-doc
以下のパッケージはアップグレードされます:
  postfix
アップグレード: 1 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。
1 個のパッケージが完全にインストールまたは削除されていません。
1,489 kB 中 0 B のアーカイブを取得する必要があります。
この操作後に追加で 3,113 kB のディスク容量が消費されます。

「了解」を押す。

「インターネットサイト」を選択します。

パッケージを事前設定しています ...
(データベースを読み込んでいます ... 現在 70120 個のファイルとディレクトリがイン ストールされています。)
postfix 2.9.6-2 を (.../postfix_2.9.6-2_armhf.deb で) 置換するための準備をしています ...
grep: /etc/postfix/master.cf: No such file or directory
grep: /etc/postfix/master.cf: No such file or directory
postfix を展開し、置換しています...
man-db のトリガを処理しています ...
postfix (2.9.6-2) を設定しています ...
グループ `postfix' (グループ ID 111) を追加しています...
完了。
システムユーザ `postfix' (UID 107) を追加しています...
新しいユーザ `postfix' (UID 107) をグループ `postfix' に追加しています...
ホームディレクトリ `/var/spool/postfix' は作成しません。
Creating /etc/postfix/dynamicmaps.cf
Adding tcp map entry to /etc/postfix/dynamicmaps.cf
Adding sqlite map entry to /etc/postfix/dynamicmaps.cf
グループ `postdrop' (グループ ID 112) を追加しています...
完了。
setting myhostname: raspberrypi
setting alias maps
setting alias database
changing /etc/mailname to oem203.net
setting myorigin
setting destinations: oem203.net, raspberrypi, localhost.localdomain, localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
/etc/aliases does not exist, creating it.
WARNING: /etc/aliases exists, but does not have a root alias.
 
Postfix is now set up with a default configuration.  If you need to make
changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).
 
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
 
Running newaliases
newaliases: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postalias: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
[....] Stopping Postfix Mail Transport Agent: postfixpostmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
. ok
[....] Starting Postfix Mail Transport Agent: postfixpostmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmulti: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postfix: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
. ok

インストール完了後は「/etc/postfix/main.cf」の設定を行います。

vi /etc/postfix/main.cf

以下の様に設定

myhostname = 自分のドメイン名
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = 自分のドメイン名, raspberrypi, localhost.localdomain, localhost
relayhost = [プロパイダのメールサーバーのアドレス]:25
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 10.1.1.0/24(自分のネットワークを追加)
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
home_mailbox = Maildir/
 
smtpd_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_local_domain = $myhostname
smtp_sasl_mechanism_filter = plain
smtpd_recipient_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_unauth_destination
smtpd_sasl_security_options = noanonymous

SASLをインストールする

apt-get install sasl2-bin libsasl2-modules libsasl2-2

「etc/default/saslauthd」を開きます。

vi etc/default/saslauthd

以下の様に書き換えて下さい。

...
START=yes
...
MECHANISMS="pam"
...
# chrootを使っている場合のみ以下を変更します。
#OPTIONS="-c -m /var/run/saslauthd"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

次に「/etc/postfix/sasl/smtpd.conf」を開きます。

vi /etc/postfix/sasl/smtpd.conf

以下の様に書き換えて下さい。

pwcheck_method: saslauthd
mech_list: plain login

フォルダを生成しておきます。

mkdir -p /var/spool/postfix/var/run/saslauthd

グループを確認します。

root@raspberrypi:/home/pi# ls -l /var/spool/postfix/var/run/
合計 4
drwx--x--- 2 root sasl 4096  8月 14 04:34 saslauthd

postfixがグループに所属していないため追加します。
「/etc/group」を開きます。

vi /etc/group

以下の様に編集する。

sasl:x:45:postfix

設定が終わったら再起動させる。

/etc/init.d/postfix restart

以上で設定は完了です。

Dovecot インストール

sudo apt-get install dovecot-pop3d
vi /etc/dovecot/dovecot.conf
pi@raspberrypi ~ $ sudo vi /etc/dovecot/dovecot.conf
# 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 = *
(中略)
disable_plaintext_auth = no
sudo service dovecot start
vi /etc/dovecot/conf.d/10-mail.conf
# See doc/wiki/Variables.txt for full list. Some examples:
#
#   mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
mail_location = maildir:~/Maildir
sudo service dovecot restart

ポート25番と110番を解放しておこう