インストール時configファイル内はローカルネットワークの設定がなされているので、幾つかの項目を修正と追加でOK! だけど、ローカルであっても出来ればTLSの仕業で設置するのが良さそうなので試してみた。
## postfix インストールと設定
1 2 3 |
$ sudo apt -y install postfix *Postfixを起動する $ sudo /etc/init.d/postfix start |
# 設定ファイルの編集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ sudo vim /etc/postfix/main.cf mydomain = Home-VM.local myorigin = $mydomain inet_interfaces = all ←追記 inet_protocols = ipv4 ←追記 mydestination = $myhostname, localhost.$mydomain, localhost, Home-VM.local ←追記 #mailbox_command = procmail -a "$EXTENSION" ←# home_mailbox ~ Maildir/ ←追記 # SMTP-Auth用'Dovecotを使う設定) smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname smtpd_recipient_retrictions= permit_mynetworks,permit_auth_distination,permit_sasl_authenticated,reject $ sudo /etc/init.d/postfix restart |
# 各configファイルの編集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# メールボックスの保存先を指定する(Postfixのhome_mailboxと同じ場所) $ sudo vi /etc/dovecot/conf.d/10-mail.conf mail_location = maildir:~/mailbox # Postfix smtp-auth ←95行目辺り コメントアウトと追記 unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } # master.cfをオープンして、以下の行のコメントを解除 $ sudo vi /etc/postfix/master.cf submission inet n - n - - smtpd -o syslog_name=postfix/submission -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject # Postfix SMTPサーバRSA証明書関連の設定 $ sudo vi /etc/postfix/main.cf ←コメントアウトの確認 smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache |
# main.cfの内容をチェック
1 2 |
$ postconf -d $ postconf -n |
# エイリアスを更新
1 2 |
$ sudo newaliases $ sudo /etc/init.d/postfix restart |
# メールボックスの作成
1 |
$ sudo mkdir /home/user/Maildir |
# Postfixを再起動して、Listenしているポートを確認
1 |
$ sudo netstat -anp | grep "master" | grep "0.0.0.0" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
---25ポート確認--- $ telnet localhost 25 Trying ::1... Connected to localhost. Escape character is '^]'. 220 mail.localhost ESMTP Postfix (Ubuntu) ehlo localhost 250-mail.localhost 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250 SMTPUTF8 QUIT 221 2.0.0 Bye Connection closed by foreign host. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
---端末で送信--- $ telnet localhost 25 Trying ::1... Connected to localhost. Escape character is '^]'. 220 mail.localhost ESMTP Postfix (Ubuntu) helo localhost ←入力 250 mail.localhost mail from: <user>@Home-VM.local ←mailから入力 250 2.1.0 Ok rcpt to: <user>@Home-VM.local ←rcptから入力 250 2.1.5 Ok data ←入力 354 End data with <CR><LF>.<CR><LF> helo world ←入力(メール) . ←入力(送信) 250 2.0.0 Ok: queued as xxxxxxxxx quit ←入力(終了) 221 2.0.0 Bye Connection closed by foreign host. |
# メールコマンドで受信できるように「mailutils」をインストール
1 2 3 4 5 |
$ sudo apt install mailutils *自分宛にメールを送信 mail <user>@Home-VM.local *正しく受信できることを確認 mail -f ~/Maildir |
## dovecot インストールと設定
1 2 |
$ sudo apt -y install dovecot-core dovecot-pop3d dovecot-imapd $ sudo /etc/init.d/dovecot start |
# 各configファイルの編集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ sudo vi /etc/dovecot/dovecot.conf ←IPv4のみListen listen = * $ sudo vi /etc/dovecot/conf.d/10-auth.conf ←平文テキストでも認証可能とする disable_plaintext_auth = yes # 10-mail.confの編集 $ sudo vim /etc/dovecot/conf.d/10-mail.conf ←Postfixのmailboxと同じ場所 mail_location = maildir:~/Maildir $ sudo vi /etc/dovecot/conf.d/10-master.conf ←95行目辺りコメントアウトと追記 # postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } |
# postfixとdovecotの再起動
1 2 |
$ sudo /etc/init.d/postfix restart $ sudo /etc/init.d/dovecot restart |
今のところプライベートIPは固定していないのとドメイン取得しての構築ではないので、ポート587と465は使えないがポート25(STARTTLS)でローカル内での接続、という事で外部へはOSBLOG_OSSHINETのメールサーバの利用となる。取り合えずは準備できたので良しとした。