Postfix Memo

自宅サーバでPostfixを使うときの設定メモ。

方針

環境

ソフトウェアはすべて ports からインストール。

サーバはLANにつながっていて、外からのport 25へのアクセスは サーバのport 25にルータでポートフォワードされているとします。

自宅LANのネットワークアドレス 192.168.0.0/24
自宅サーバのホスト名 myhost.example.org
ISPのSMTPサーバ smtpserver.isp.example.com
ClamSMTPの待ちうけアドレス 127.0.0.1
ClamSMTPの待ちうけポート 10025
ClamSMTPの送り出しポート 10026
QuickMLの待ち受けポート 20025
QuickML用サブドメイン lists.example.org

Postfixの設定

main.cf

myhostname = myhost.example.org
mydomain = example.org
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.0.0/24, 127.0.0.0/8
relayhost = [smtpserver.isp.example.com]
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
content_filter = scan:[127.0.0.1]:10025
receive_override_options = no_address_mappings
# Setting for QuickML
transport_maps = hash:/usr/local/etc/postfix/transport
smtpd_authorized_verp_clients = 127.0.0.0/8

master.cf

# AV scan filter (used by content_filter)
scan      unix  -       -       n       -       16      smtp
       -o smtp_send_xforward_command=yes
# For injecting mail back into postfix from the filter
127.0.0.1:10026 inet  n -       n       -       16      smtpd
       -o content_filter=
       -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
       -o smtpd_helo_restrictions=
       -o smtpd_client_restrictions=
       -o smtpd_sender_restrictions=
       -o smtpd_recipient_restrictions=permit_mynetworks,reject
       -o mynetworks_style=host
       -o smtpd_authorized_xforward_hosts=127.0.0.0/8

transport

lists.example.org smtp:[localhost]:20025

以下を実行してから postfix を reload する。

# postmap hash:/usr/local/etc/postfix/transport

ClamSMTPの設定

clamsmtpd.conf

Listen: 127.0.0.1:10025
TempDirectory: /var/tmp/clamsmtp
Quarantine: on
VirusAction: /usr/local/sbin/virusalert.sh

/usr/local/sbin/virusalert.sh

ウイルスメールがきたらメールを送るスクリプト

#!/bin/sh
FROM='ClamSMTP <clamav@example.org>'
TO='virusalert@example.org'
MAILER='/usr/sbin/sendmail -it'
$MAILER <<EOM
From: $FROM
To: $TO
Subject: VIRUS ($VIRUS) FROM ($SENDER)
A virus ($VIRUS) was found.
The message has been quarantined as:
   $EMAIL
The email recipients:
   $RECIPIENTS
EOM

QuickMLの設定

quickmlrc

Config = {
  :user => "quickml",
  :group => "quickml",
  :port => 20025,
  :bind_address => "127.0.0.1",
:smtp_host => 'localhost',
:smtp_port => 25,
:domain => 'lists.example.org',
:postmaster => "postmaster@example.org",

変更履歴

Nobuyuki Honda