LoginSignup
11
16

More than 3 years have passed since last update.

Ubuntu 20.10 で Postfix,Dovecot を使う

Last updated at Posted at 2018-05-15

Ubuntu 20.10 に Postfix と Dovecot をインストールしました。

1) Postfix のインストール

sudo apt install postfix

サーバーの選択は、インターネットを選びました。

設定ファイルの変更は、クライアントの IP アドレスの登録だけです。

/etc/postfix/main.cf
 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 153.211.60.100

2) Dovecot のインストール

sudo apt install dovecot-common dovecot-imapd dovecot-pop3d

設定の変更は不要です。

3) 起動していることの確認
インストールするだけで起動しますが、その確認

sudo systemctl status postfix
sudo systemctl status dovecot

4) 送信のテスト

サーバー内で

telnet localhost 25

クライアントから

telnet サーバー名 25
$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 133-130-124-85 ESMTP Postfix (Ubuntu)
helo example.com
250 113-120-114-65
mail from: uchida@example.com
250 2.1.0 Ok
rcpt to: aaa@target.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject: Test mail
From: uchida@example.com
Good Afternoon.
.
250 2.0.0 Ok: queued as 0BF36127
quit
221 2.0.0 Bye
Connection closed by foreign host.

次のようなスクリプトでもテストが出来ます。

netcat localhost 25 < in01.txt
in01.txt
helo example.com
mail from: uchida@example.com
rcpt to: aaa@target.com
data
Subject: Test mail on Jul/05/2020
From: uchida@example.com
Good Afternoon.
.
quit

メールコマンドでのテスト

$ mail -s "Test mail" aaa@target.com
Cc: 
From: uchida@example.com
Hello
Good Evening
Cntrl + D で終了

スクリプトにすると

mail -s "Test mail" aaa@target.com < m01.txt
m01.txt
From: uchida@example.com
Hello
Good Evening

5) 受信のテスト
 Thunderbird などでメールを受信します。

6) openssl で Dovecot のテスト

$openssl s_client -connect example.com:995 -quiet
(省略)
+OK Dovecot (Ubuntu) ready.
user scott
+OK
pass aaaaaa
+OK Logged in.
list
+OK 4 messages:
1 1212
2 1256
3 1244
4 997
.

この状態で、hi-ho.ne.jp yahoo.co.jp nifty.com などには、メールを送れますが、 gmail.com には送れません。

gmail.com に送ろうとすると、次のエラーが出ます。

host gmail-smtp-in.l.google.com[2404:6800:4008:c01::1b]
    said: 550-5.7.1 This message does not have authentication information or
    fails to pass 550-5.7.1 authentication checks. To best protect our users
    from spam, the 550-5.7.1 message has been blocked.

これは、DNS サーバーで、SPF レコード (TXT) を設定すれば解消します。
私は、onamae.com で設定しました。

CentOS 7 の設定はこちらです。
CentOS7 で Postfix,Dovecot を使う

11
16
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
11
16