1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

おうちサーバー構築報告:PostfixでCatchAll(AllDomain)設定

Last updated at Posted at 2025-01-05

能書き

おうちサーバー構築報告:予告からのおうちサーバー構築の続きです。

あらゆる宛先のメールを1人のユーザーに転送して全部受信する設定は、CatchAllと言うらしいですな。恥ずかしながら知りませんでした。

以前も似たような設定をしましたが、CatchAll設定を踏まえて少し改良しました。

目標

  • メール専用コンテナにPostfixをインストール
    • CatchAll設定、但し全ドメインの全ユーザーを受信対象とする
    • 非公開を前提に、SMTP認証しない
    • ローカル配信はDovecotのLMTPを利用

今回の設定で公開すると、息つく暇も無く迷惑メールの踏み台にされる&メール爆弾の如く迷惑メールが届く筈ですので、絶対に公開しないで下さい。

そんな不自由なメールサーバーを立てる理由は、GitLabです。この後でGitLabサーバーを立てたいと考えていますが、そこでメールサーバーとの連携が必要になります。これが今のモチベーションになっています。

参考文献

Postfixインストールと設定

我が家のメール専用コンテナのIPアドレスは172.16.1.102で名前はmailです。

サーバー172.16.1.102ユーザー名root
CATCHALL_USER=taro
サーバー172.16.1.102ユーザー名root
apt update
apt upgrade -y
apt install -y postfix
サーバー172.16.1.102ユーザー名root
cd /etc
svn st | grep "^?" | cut -b9- | sudo xargs -I{} find {} -type f -or -type d -or -type l | xargs -rt svn add
svn ci -m"install postfix"

cat <<"___" >/etc/postfix/main.cf
compatibility_level = 3.6

mydomain = local
myhostname = mail.$mydomain
myorigin = $myhostname

inet_protocols = ipv4
inet_interfaces = all

mydestination = $mydomain
local_recipient_maps =

mynetworks = 127.0.0.0/8, 172.16.0.0/16

alias_maps = hash:/etc/aliases
mailbox_transport = lmtp:inet:127.0.0.1:24

smtpd_banner = $myhostname ESMTP
biff = no

readme_directory = no

virtual_alias_maps = regexp:/etc/postfix/virtual_users

mailbox_size_limit = 0
recipient_delimiter = +

# appending .domain is the MUA's job.
append_dot_mydomain = no
___
echo /@.*/$'\t'$CATCHALL_USER@local >/etc/postfix/virtual_users
postmap /etc/postfix/virtual_users
cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
systemctl restart postfix

svn st | grep "^?" | cut -b9- | sudo xargs -I{} find {} -type f -or -type d -or -type l | xargs -rt svn add
svn ci -m"setting postfix"

動作確認

メール受信ユーザー宛

私の環境で唯一のメール受信ユーザーtaroにメールしてみます。どのマシン(コンテナ、仮想マシン、Windows)で送信実験しても良いんですが、Linuxならncコマンドが使えるし、とりあえず172.16.1.100で実施してみます。

サーバー172.16.1.100ユーザー名ansible
nc -C 172.16.1.102 25 <<___
ehlo sender.local
mail from: ubuntu@example.com
rcpt to: taro@local
data
From: ubuntu@example.com
To: taro@local
Subject: test1

hello, taro
$(date +"%Y/%m/%d %H:%M:%S")
.
quit
___

マシン172.16.1.102taroに届いた筈のメールを確認。

サーバー172.16.1.102ユーザー名root
cd /home/taro/Maildir/new
ls -t | head -n1 | xargs cat

知らないユーザー宛

メール受信ではない(しかもUbuntuにも未登録の)ユーザーhanakoにメールしてみます。

サーバー172.16.1.100ユーザー名ansible
nc -C 172.16.1.102 25 <<___
ehlo sender.local
mail from: ubuntu@example.com
rcpt to: hanako@local
data
From: ubuntu@example.com
To: hanako@local
Subject: test2

hello, hanako
$(date +"%Y/%m/%d %H:%M:%S")
.
quit
___

これもtaroに届いた筈です。

サーバー172.16.1.102ユーザー名root
cd /home/taro/Maildir/new
ls -t | head -n1 | xargs cat

知らないドメインの知らないユーザー宛

メールアドレスhanako@example.comにメールしてみます。

サーバー172.16.1.100ユーザー名ansible
nc -C 172.16.1.102 25 <<___
ehlo sender.local
mail from: ubuntu@example.com
rcpt to: hanako@example.com
data
From: ubuntu@example.com
To: hanako@example.com
Subject: test3

hello, hanako@example.com
$(date +"%Y/%m/%d %H:%M:%S")
.
quit
___

これもtaroに届いた筈です。

サーバー172.16.1.102ユーザー名root
cd /home/taro/Maildir/new
ls -t | head -n1 | xargs cat

仕舞い

全ドメインの全ユーザー宛のメールを受信するメールサーバーMTAを設定できました。前回のDovecotと合わせて、メールサーバー一式が揃いました。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?