「Postfix」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(同期)
4行目: 4行目:
 
{{Related|Postfix と SASL}}
 
{{Related|Postfix と SASL}}
 
{{Related|Amavis}}
 
{{Related|Amavis}}
  +
{{Related|仮想ユーザーメールシステム}}
{{Related4|Virtual user mail system}}
 
 
{{Related4|Courier MTA}}
 
{{Related4|Courier MTA}}
  +
{{Related|Exim}}
{{Related3|Exim with remote SMTP server|Exim}}
 
 
{{Related4|OpenSMTPD}}
 
{{Related4|OpenSMTPD}}
  +
{{Related4|OpenDMARC}}
  +
{{Related4|OpenDKIM}}
 
{{Related articles end}}
 
{{Related articles end}}
 
[http://www.postfix.org/ Postfix のサイト] より:
 
[http://www.postfix.org/ Postfix のサイト] より:
17行目: 19行目:
   
 
{{Pkg|postfix}} パッケージを[[インストール]]してください。
 
{{Pkg|postfix}} パッケージを[[インストール]]してください。
 
=== DNS レコード ===
 
 
メールホストを MX レコードに設定する必要があります。通常はドメインプロバイダの設定インターフェイスから設定できます。
 
 
メール交換レコード (MX レコード) は Domain Name System におけるリソースレコードの一つで、受取人のドメインを代表してメールメッセージを受け取るメールサーバーを指定します。
 
 
メールメッセージがインターネットから送られると、メール転送エージェントが Domain Name System から受取人のドメイン名の MX レコードを聞き出します。このクエリに対して、メール交換サーバーのホスト名のリストが返ってきます。次に、エージェントはそれらのサーバーのどれか一つと (設定番号が一番若いサーバーから順番に) SMTP 接続を確立して、接続が出来た最初のサーバーにメールを配送します。
 
 
{{Note|Some mail servers will not deliver mail to you if your MX record points to a CNAME. For best results, always point an MX record to an A record definition. For more information, see e.g. [[Wikipedia:List of DNS record types|Wikipedia's List of DNS Record Types]].}}
 
   
 
== 設定 ==
 
== 設定 ==
35行目: 27行目:
   
 
[[#Secure SMTP]] に書かれているように Secure SMTP を有効化することを推奨します。
 
[[#Secure SMTP]] に書かれているように Secure SMTP を有効化することを推奨します。
  +
  +
送受信されるメールの暗号化については [http://www.postfix.org/TLS_README.html このページ] を見てください。
   
 
=== main.cf ===
 
=== main.cf ===
50行目: 44行目:
   
 
*{{ic|mydestination}} はローカルユーザーのルックアップです。
 
*{{ic|mydestination}} はローカルユーザーのルックアップです。
:{{bc|1=mydestination = $myhostname, localhost.$mydomain, localhost}}
+
:{{bc|1=mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain}}
   
*{{ic|mynetworks}} と {{ic|mynetwork_style}} はリレーを制御し、許可するユーザーを指定します。リレーは設定しません。
+
*{{ic|mynetworks}} と {{ic|mynetworks_style}} はリレーを制御し、許可するユーザーを指定します。リレーは設定しません。
 
:{{ic|mynetwork_style}} は host に設定して、スタンドアロンの Postfix ホストを作成し、ウェブメールを利用できるようにします。リレーは行わず、他の MTA も使いません。ただのウェブメールです。
 
:{{ic|mynetwork_style}} は host に設定して、スタンドアロンの Postfix ホストを作成し、ウェブメールを利用できるようにします。リレーは行わず、他の MTA も使いません。ただのウェブメールです。
 
:{{bc|1=mynetworks_style = host}}
 
:{{bc|1=mynetworks_style = host}}
59行目: 53行目:
 
:{{bc|1=relay_domains = }}
 
:{{bc|1=relay_domains = }}
   
*{{ic|home_mailbox}} or {{ic|mail_spool_directory}} control how mail is delivered/stored for the users.
+
*{{ic|home_mailbox}} {{ic|mail_spool_directory}} はユーザーのメールの保存場所を指定します。
:If set, {{ic|mail_spool_directory}} specifies an absolute path where mail gets delivered. By default Postfix stores mails in {{ic|/var/spool/mail}}.
+
:設定する場合、{{ic|mail_spool_directory}} にはメールを保存するディレクトリを絶対パスで指定します。デフォルトでは Postfix {{ic|/var/spool/mail}} にメールを保存します。
   
:{{bc|1=home_spool_directory = /home/vmailer}}
+
:{{bc|1=mail_spool_directory = /home/vmailer}}
   
 
:Alternatively, if set, {{ic|home_mailbox}} specifies a mailbox relative to the user's home directory where mail gets delivered (eg: /home/vmailer).
 
:Alternatively, if set, {{ic|home_mailbox}} specifies a mailbox relative to the user's home directory where mail gets delivered (eg: /home/vmailer).
81行目: 75行目:
 
}}
 
}}
   
==== デフォルトメッセージとメールボックスの容量制限 ====
+
==== メッセージとメールボックスの容量制限 ====
   
  +
Postfix はデフォルトでメッセージとメールボックスの容量を制限します。{{ic|message_size_limit}} にはメッセージの最大容量をバイト数で指定します (デフォルトは 10240000 です)。{{ic|mailbox_size_limit}} はローカルのメールボックスや maildir ファイルの最大容量を決めます (デフォルトは 51200000 で、制限したくない場合は 0 に設定します)。配達時に書き出されるあらゆるファイルの容量を制限します。ローカルの配達エージェントによって実行された外部コマンド (procmail) で書き出されるファイルも含みます。バウンスメッセージの通知が生成される場合、{{ic|/var/spool/mail}} 下のローカルのメールボックスの容量を確認して、postconf を使って容量制限を確認してください:
Postfix imposes both message and mailbox size limits by default. The message_size_limit controls the maximum size in bytes of a message, including envelope information. (default 10240000) The mailbox_size_limit controls the maximum size of any local individual mailbox or maildir file. This limits the size of '''any''' file that is written to upon local delivery, '''including files written by external commands''' (i.e. procmail) that are executed by the local delivery agent. (default is 51200000, set to 0 for no limit) If bounced message notifications are generated, check the size of the local mailbox under {{ic|/var/spool/mail}} and use postconf to check these size limits:
 
   
# postconf -d mailbox_size_limit
+
# postconf mailbox_size_limit
 
mailbox_size_limit = 51200000
 
mailbox_size_limit = 51200000
# postconf -d message_size_limit
+
# postconf message_size_limit
 
message_size_limit = 10240000
 
message_size_limit = 10240000
   
110行目: 104行目:
 
}}}}
 
}}}}
   
== ローカルメール ==
+
=== ローカルメール ===
   
  +
({{ic|/etc/passwd}} に記述されている) ローカルのシステムユーザーにしかメールを配達しないようにするには、{{ic|/etc/postfix/main.cf}} を以下のように変更してください:
To only deliver mail to local system users (that are in {{ic|/etc/passwd}}), you only need to change the following lines in {{ic|/etc/postfix/main.cf}}. Uncomment them and modify them to the specifics listed below. Everything else can be left as installed.
 
   
  +
myhostname = localhost
  +
mydomain = localdomain
 
mydestination = $myhostname, localhost.$mydomain, localhost
 
mydestination = $myhostname, localhost.$mydomain, localhost
inet_interfaces = loopback-only
+
inet_interfaces = $myhostname, localhost
 
mynetworks_style = host
 
mynetworks_style = host
  +
default_transport = error: outside mail is not deliverable
append_dot_mydomain = no
 
default_transport = error: Local delivery only!
 
   
  +
他の設定を変更する必要はありません。上記のように設定したら、[[#エイリアス|エイリアス]]を設定して [[#Postfix の起動|Postfix を起動]]してください。
== バーチャルメール ==
 
  +
  +
=== バーチャルメール ===
 
バーチャルメールはユーザーアカウントにマッピングされないメールです ({{ic|/etc/passwd}})。
 
バーチャルメールはユーザーアカウントにマッピングされないメールです ({{ic|/etc/passwd}})。
   
セットアップする方法は [[en2:Virtual user mail system|Virtual user mail system]] を見てさい。
+
セットアップする方法は[[仮想ユーザーメールシステム]]を見てください。
   
== Postfix check ==
+
=== DNS レコード ===
  +
  +
メールホストを MX レコードに設定する必要があります。通常はドメインプロバイダの設定インターフェイスから設定できます。
  +
  +
メール交換レコード (MX レコード) は Domain Name System におけるリソースレコードの一つで、受取人のドメインを代表してメールメッセージを受け取るメールサーバーを指定します。
  +
  +
メールメッセージがインターネットから送られると、メール転送エージェントが Domain Name System から受取人のドメイン名の MX レコードを聞き出します。このクエリに対して、メール交換サーバーのホスト名のリストが返ってきます。次に、エージェントはそれらのサーバーのどれか一つと (設定番号が一番若いサーバーから順番に) SMTP 接続を確立して、接続が出来た最初のサーバーにメールを配送します。
  +
  +
{{Note|Some mail servers will not deliver mail to you if your MX record points to a CNAME. For best results, always point an MX record to an A record definition. For more information, see e.g. [[Wikipedia:List of DNS record types|Wikipedia's List of DNS Record Types]].}}
  +
  +
=== 設定のチェック ===
   
 
{{ic|postfix check}} コマンドを実行してください。設定ファイルで間違っている部分が出力されます。
 
{{ic|postfix check}} コマンドを実行してください。設定ファイルで間違っている部分が出力されます。
131行目: 138行目:
 
全ての設定を確認したいときは、{{ic|postconf}} と入力します。デフォルト設定との差異点を確認したいときは、{{ic|postconf -n}} を実行してみてください。
 
全ての設定を確認したいときは、{{ic|postconf}} と入力します。デフォルト設定との差異点を確認したいときは、{{ic|postconf -n}} を実行してみてください。
   
== Postfix の起動とテスト ==
+
== Postfix の起動 ==
  +
  +
{{Note|[[#エイリアス|エイリアス]]を全く設定していない場合でも Postfix を起動するには最低でも1回は {{ic|newaliases}} を実行する必要があります。}}
   
 
{{ic|postfix.service}} を[[systemd#ユニットを使う|起動・有効化]]してください。
 
{{ic|postfix.service}} を[[systemd#ユニットを使う|起動・有効化]]してください。
   
  +
== テスト ==
Now lets see if Postfix is going to deliver mail for our test user.
 
  +
  +
Postfix がテストユーザーにメールを配達できるかどうか確認してみましょう:
 
{{bc|
 
{{bc|
 
nc servername 25
 
nc servername 25
150行目: 161行目:
   
 
451 4.3.0 <lisi@test.com>:Temporary lookup failure
 
451 4.3.0 <lisi@test.com>:Temporary lookup failure
  +
MySQL のユーザー名やパスワードが間違っているか、あるいは MySQL のソケットが正しい場所に存在しません。
Maybe you have entered the wrong user/password for MySQL or the MySQL socket is not in the right place.
 
  +
  +
Postfix を起動する前に newaliases を実行していなかった場合も上記のエラーが発生します。Postfix をローカルのみで使用するのであれば MySQL は不要です。
   
 
550 5.1.1 <email@spam.me>: Recipient address rejected: User unknown in virtual mailbox table.
 
550 5.1.1 <email@spam.me>: Recipient address rejected: User unknown in virtual mailbox table.
Double check content of mysql_virtual_mailboxes.cf and check the main.cf for mydestination
+
{{ic|mysql_virtual_mailboxes.cf}} の中身や {{ic|main.cf}} {{ic|mydestination}} をチェックしてください。
   
 
=== メールを受け取ったことを確認 ===
 
=== メールを受け取ったことを確認 ===
169行目: 182行目:
 
最後のエントリが実際のメールです。これで動作していることが確認できます。
 
最後のエントリが実際のメールです。これで動作していることが確認できます。
   
== Extra ==
+
== Tips and tricks ==
   
 
=== PostfixAdmin ===
 
=== PostfixAdmin ===
232行目: 245行目:
   
 
=== Secure SMTP ===
 
=== Secure SMTP ===
  +
  +
詳しくは [http://www.postfix.org/TLS_README.html Postfix TLS Support] を見てください。
   
 
==== STARTTLS over SMTP (ポート 587) ====
 
==== STARTTLS over SMTP (ポート 587) ====
   
To enable STARTTLS over SMTP (port 587, the proper way of securing SMTP), uncomment these lines in
+
To enable STARTTLS over SMTP (port 587, the proper way of securing SMTP), add the following lines to {{ic|main.cf}}
   
{{hc|/etc/postfix/master.cf|<nowiki>
+
{{hc|/etc/postfix/main.cf|2=
  +
smtpd_tls_security_level = may
smtp inet n - n - - smtpd
 
  +
smtpd_tls_cert_file = '''/path/to/cert.pem'''
  +
smtpd_tls_key_file = '''/path/to/key.pem'''
  +
}}
  +
  +
Also in {{ic|master.cf}} find and remove the comment from the following line to enable the service on that port:
  +
  +
{{hc|/etc/postfix/master.cf|2=
 
submission inet n - n - - smtpd
 
submission inet n - n - - smtpd
  +
}}
-o smtpd_tls_security_level=encrypt
 
-o smtpd_sasl_auth_enable=yes
 
</nowiki>}}
 
   
 
If you need support for the deprecated SMTPS port 465, read the next section.
 
If you need support for the deprecated SMTPS port 465, read the next section.
272行目: 292行目:
 
{{ic|/etc/mail/spamassassin/local.cf}} を開いて必要に応じて設定して下さい。
 
{{ic|/etc/mail/spamassassin/local.cf}} を開いて必要に応じて設定して下さい。
   
SpamAssassin のマッチパタンを更新:
+
==== SpamAssassin のルの更新 ====
  +
  +
SpamAssassin のマッチパターンを更新してコンパイル:
 
# sa-update
 
# sa-update
  +
# sa-compile
  +
  +
上記のコマンドを定期的に実行したい場合、[[Systemd/タイマー]]を使用するのが良いでしょう。
  +
  +
以下のサービスを作成してください:
  +
{{hc|1=/etc/systemd/system/spamassassin-update.service|2=
  +
[Unit]
  +
Description=spamassassin housekeeping stuff
  +
  +
[Service]
  +
User=spamd
  +
Group=spamd
  +
Type=oneshot
  +
ExecStart=-/usr/bin/vendor_perl/sa-update --allowplugins #You can remove the allowplugins options if you do not want direct plugin updates from SA.
  +
ExecStart=-/usr/bin/vendor_perl/sa-compile
  +
# You can automatically train SA's bayes filter by uncommenting this line and specifying the path to a mailbox where you store email that is spam (for ex this could be yours or your users manually reported spam)
  +
#ExecStart=-/usr/bin/vendor_perl/sa-learn --spam <path to your spam>
  +
}}
  +
  +
そして、上記のサービスを毎日実行するタイマーを作成してください:
  +
{{hc|1=/etc/systemd/system/spamassassin-update.timer|2=
  +
[Unit]
  +
Description=spamassassin house keeping
  +
  +
[Timer]
  +
OnCalendar=daily
  +
Persistent=true
  +
  +
[Install]
  +
WantedBy=timers.target
  +
}}
  +
  +
Finally, you'll need to modify your Spamassassin systemd service file so that it knows to restart itself to read the new rules. Copy the bundled service file to a custom service file:
  +
{{bc|1=
  +
# cp /usr/lib/systemd/system/spamassassin.service /etc/systemd/system
  +
}}
  +
  +
And edit the newly created {{ic|/etc/systemd/system/spamassassin.service}} to include:
  +
{{bc|1=
  +
[Unit]
  +
PartOf=spamassassin-update.service
  +
}}
  +
  +
This will ensure that Spamassassin's spamd is restarted just before the timer runs. This means the rules will be available the next day if your timer runs daily. This is so that there is no long service interruption while {{ic|sa.service}} runs as it takes a while to compile rules.
  +
  +
そして {{ic|spamassassin-update.service}} を[[起動]]・[[有効化]]してください。
  +
  +
==== SpamAssassin のスタンドアロン設定 ====
   
 
{{Note|If you want to combine SpamAssassin and Dovecot Mail Filtering, ignore the next two lines and continue further down instead.}}
 
{{Note|If you want to combine SpamAssassin and Dovecot Mail Filtering, ignore the next two lines and continue further down instead.}}
291行目: 361行目:
 
上記の設定をしたら {{ic|spamassassin.service}} を[[起動]]できます。
 
上記の設定をしたら {{ic|spamassassin.service}} を[[起動]]できます。
   
==== SpamAssassin と Dovecot LDA / Sieve を組み合わせる (Mailfiltering) ====
+
==== SpamAssassin と Dovecot LDA / Sieve を組み合わせる (メールフィルタリング) ====
 
[[Dovecot#Sieve]] に書かれているように LDA と Sieve-Plugin をセットアップします。ただし最後の行 {{ic|mailbox_command... }} は無視してください。
 
[[Dovecot#Sieve]] に書かれているように LDA と Sieve-Plugin をセットアップします。ただし最後の行 {{ic|mailbox_command... }} は無視してください。
   
304行目: 374行目:
 
[[Dovecot#Sieve]] に書かれているように LMTP と Sieve をセットアップします。
 
[[Dovecot#Sieve]] に書かれているように LMTP と Sieve をセットアップします。
   
{{ic|/etc/dovecot/conf.d/90-sieve.conf}} を編集して以下を追加:
+
{{ic|/etc/dovecot/conf.d/90-plugins.conf}} を編集して以下を追加:
   
sieve_before = /etc/dovecot/sieve.d/
+
sieve_before = /etc/dovecot/sieve.before.d/
 
sieve_extensions = +vnd.dovecot.filter
 
sieve_extensions = +vnd.dovecot.filter
 
sieve_plugins = sieve_extprograms
 
sieve_plugins = sieve_extprograms
  +
sieve_filter_bin_dir = /etc/dovecot/sieve-filter
  +
sieve_filter_exec_timeout = 120s #this is often needed for the long running spamassassin scans, default is otherwise 10s
   
 
ディレクトリを作成:
 
ディレクトリを作成:
314行目: 386行目:
 
# mkdir /etc/dovecot/sieve.d/
 
# mkdir /etc/dovecot/sieve.d/
   
新しいファイル {{ic|/etc/dovecot/sieve.d/spamassassin.sieve}} を以下の内容で作成:
+
新しいファイル {{ic|/etc/dovecot/sieve.before.d/spamassassin.sieve}} を以下の内容で作成:
   
 
require [ "vnd.dovecot.filter" ];
 
require [ "vnd.dovecot.filter" ];
filter "spamc" [ "--no-safe-fallback" ];
+
filter "spamc" [ "-d", "127.0.0.1', "--no-safe-fallback" ];
   
 
sieve ルール {{ic|spamassassin.svbin}} をコンパイル:
 
sieve ルール {{ic|spamassassin.svbin}} をコンパイル:
   
# cd /etc/dovecot/sieve.d
+
# cd /etc/dovecot/sieve.before.d
 
# sievec spamassassin.sieve
 
# sievec spamassassin.sieve
   
 
最後に、{{ic|dovecot.service}} を[[再起動]]してください。
 
最後に、{{ic|dovecot.service}} を[[再起動]]してください。
  +
  +
==== SpamAssassin から ClamAV を実行 ====
  +
  +
[[ClamAV]] に書かれているように clamd をインストール・設定してください。
  +
  +
上記の設定のどれかにしたがってメールシステムから SpamAssassin が呼び出されるようにしてください。
  +
  +
{{pkg|perl-cpanplus-dist-arch}} パッケージを[[インストール]]して、以下のように ClamAV の perl ライブラリをインストールしてください:
  +
  +
# /usr/bin/vendor_perl/cpanp -i File::Scan::ClamAV
  +
  +
http://wiki.apache.org/spamassassin/ClamAVPlugin から2つのファイルを {{ic|/etc/mail/spamassassin/}} に追加してください。{{ic|/etc/mail/spamassassin/clamav.pm}} を編集して {{ic|$CLAM_SOCK}} で clamd のソケットを指定してください (デフォルトでは {{ic|/var/lib/clamav/clamd.sock}} です)。
  +
  +
最後に、{{ic|spamassassin.service}} を[[再起動]]してください。
   
 
=== Razor を使う ===
 
=== Razor を使う ===
360行目: 446行目:
 
/^User-Agent: .*/ IGNORE
 
/^User-Agent: .*/ IGNORE
 
Finally, restart postfix.service
 
Finally, restart postfix.service
  +
  +
===ルールベースのメール処理===
  +
ポリシーサービスを使うことで Postfix のメール処理を簡単に設定できます。{{Pkg|postfwd}} と {{AUR|policyd}} はそのようなポリシーサービスを提供して、[[en2:SPF|SPF]] のポリシーチェックに加えて送信者や受信者のグレイリスト・ブラックリストを簡単に作ることができます。
  +
  +
ポリシーサービスはスタンドアロンなサービスであり、以下のようにして Postfix に接続します:
  +
{{hc|/etc/postfix/main.cf|<nowiki>
  +
smtpd_recipient_restrictions =
  +
...
  +
check_policy_service unix:/run/policyd.sock
  +
check_policy_service inet:127.0.0.1:10040
  +
</nowiki>}}
  +
最後にポリシーサービスを配置することで正当なメールだけでが処理されるようになり、負担が減ります。受信されたメッセージ全てが通るように permit ステートメントよりも前に配置してください。
  +
  +
=== DANE (DNSSEC) ===
  +
==== リソースレコード ====
  +
  +
{{warning|This is not a trivial section. Be aware that you make sure you know what you are doing. You better read [https://dane.sys4.de/common_mistakes Common Mistakes] before.}}
  +
  +
DANE は複数のタイプのレコードをサポートしていますが、全てが Postfix で使われるわけではありません。
  +
  +
Certificate Usage Field の0はサポートされておらず、1は3にマッピングされていて、2はオプションです。したがって "3" レコードを使用することが推奨されます。詳しくは [[DANE#リソースレコード]]を見てください。
  +
  +
==== 設定 ====
  +
Opportunistic DANE is configured this way:
  +
{{hc|/etc/postfix/main.cf|<nowiki>
  +
smtpd_use_tls = yes
  +
smtp_dns_support_level = dnssec
  +
smtp_tls_security_level = dane
  +
</nowiki>}}
  +
{{hc|/etc/postfix/master.cf|<nowiki>
  +
dane unix - - n - - smtp
  +
-o smtp_dns_support_level=dnssec
  +
-o smtp_tls_security_level=dane
  +
</nowiki>}}
  +
  +
To use per-domain policies, e.g. opportunistic DANE for example.org and mandatory DANE for example.com,
  +
use something like this:
  +
{{hc|/etc/postfix/main.cf|<nowiki>
  +
indexed = ${default_database_type}:${config_directory}/
  +
  +
# Per-destination TLS policy
  +
#
  +
smtp_tls_policy_maps = ${indexed}tls_policy
  +
  +
# default_transport = smtp, but some destinations are special:
  +
#
  +
transport_maps = ${indexed}transport
  +
</nowiki>}}
  +
  +
{{hc|transport|
  +
example.com dane
  +
example.org dane
  +
}}
  +
  +
{{hc|tls_policy|
  +
example.com dane-only
  +
}}
  +
  +
{{Note|For global mandatory DANE, change {{ic|smtp_tls_security_level}} to {{ic|dane-only}}. Be aware that this makes postfix tempfail on all delivieres that do not use DANE at all!}}
  +
  +
Full documentation is found [http://www.postfix.org/TLS_README.html#client_tls_dane here].
   
 
== 参照 ==
 
== 参照 ==

2016年10月5日 (水) 21:26時点における版

関連記事

Postfix のサイト より:

Postfix は高速で管理しやすくセキュアでありながら、同時に既存のユーザーを使えるように sendmail と互換性を保っています。そのため、外から見ると sendmail のようですが、中身は完全に別物です。

この記事では Postfix をセットアップする方法と基本的な設定ファイルの説明をします。ローカルのシステムユーザーだけが使える設定の手順と、仮想ユーザーを使う方法のリンクが存在します。

インストール

postfix パッケージをインストールしてください。

設定

master.cf

/etc/postfix/master.cf は利用するプロトコルの種類を指定できるマスター設定ファイルです。また、パイプを設定することでスパムのチェックなどを行うこともできます。

#Secure SMTP に書かれているように Secure SMTP を有効化することを推奨します。

送受信されるメールの暗号化については このページ を見てください。

main.cf

/etc/postfix/main.cf はあらゆることを設定できるメイン設定ファイルです。仮想ローカルのみの配送をする場合、以下の設定を推奨します。

  • myhostname はメールサーバーが複数のドメインを持っている場合に、プライマリドメインをメールホストにしたくないときに設定してください。DNS の A レコードと MX レコードの両方がこのホスト名を指定している必要があります。
myhostname = mail.nospam.net
  • mydomain は通常 myhostname の値から最初の部分を除いた部分になります。ドメインが信頼できないときは、手動で設定してください。
mydomain = nospam.net
  • myorigin はメールの送信元になります。通常は mydomain の値に設定します。単純なサーバーなら、これで十分です。ローカルアカウントからのメール用です。ローカル転送はしないため (送信は除く)、基本的にあまり重要ではありません。
myorigin = $mydomain
  • mydestination はローカルユーザーのルックアップです。
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  • mynetworksmynetworks_style はリレーを制御し、許可するユーザーを指定します。リレーは設定しません。
mynetwork_style は host に設定して、スタンドアロンの Postfix ホストを作成し、ウェブメールを利用できるようにします。リレーは行わず、他の MTA も使いません。ただのウェブメールです。
mynetworks_style = host
  • relaydomains は Postfix のリレー先を指定します。デフォルトの値は空です。空のままでかまいません。
relay_domains =
  • home_mailboxmail_spool_directory はユーザーのメールの保存場所を指定します。
設定する場合、mail_spool_directory にはメールを保存するディレクトリを絶対パスで指定します。デフォルトでは Postfix は /var/spool/mail にメールを保存します。
mail_spool_directory = /home/vmailer
Alternatively, if set, home_mailbox specifies a mailbox relative to the user's home directory where mail gets delivered (eg: /home/vmailer).
Courier-IMAP requires "Maildir" format, so you must set it like the following example with trailing slash:
home_mailbox = Maildir/
警告: If you plan on implementing SSL/TLS, please respond safely to POODLE and FREAK/Logjam by adding the following to your configuration:
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3
smtpd_tls_protocols=!SSLv2,!SSLv3
smtp_tls_protocols=!SSLv2,!SSLv3
smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC4, MD5, PSK, aECDH, EDH-DSS-DES-CBC3-SHA, EDH-RSA-DES-CDC3-SHA, KRB5-DE5, CBC3-SHA

Then, generate a dhparam file by following these instructions and then adding the following to your configuration:

smtpd_tls_dh1024_param_file = ${config_directory}/dhparams.pem

メッセージとメールボックスの容量制限

Postfix はデフォルトでメッセージとメールボックスの容量を制限します。message_size_limit にはメッセージの最大容量をバイト数で指定します (デフォルトは 10240000 です)。mailbox_size_limit はローカルのメールボックスや maildir ファイルの最大容量を決めます (デフォルトは 51200000 で、制限したくない場合は 0 に設定します)。配達時に書き出されるあらゆるファイルの容量を制限します。ローカルの配達エージェントによって実行された外部コマンド (procmail) で書き出されるファイルも含みます。バウンスメッセージの通知が生成される場合、/var/spool/mail 下のローカルのメールボックスの容量を確認して、postconf を使って容量制限を確認してください:

# postconf mailbox_size_limit
mailbox_size_limit = 51200000
# postconf message_size_limit
message_size_limit = 10240000

エイリアス

エイリアス (別名フォワーダー) は /etc/postfix/aliases で指定できます。

root でメールを読むのはよろしくないので root に届いたメールは全て他のアカウントにマッピングするべきでしょう。

以下の行をアンコメントして、you を実際のアカウントに置き換えてください:

root: you

/etc/postfix/aliases の編集を終えたら postalias コマンドを実行してください:

postalias /etc/postfix/aliases

後で変更するときは:

newaliases
ヒント: Alternatively you can create the file ~/.forward, e.g. /root/.forward for root. Specify the user to whom root mail should be forwarded, e.g. user@localhost.
/root/.forward
user@localhost

ローカルメール

(/etc/passwd に記述されている) ローカルのシステムユーザーにしかメールを配達しないようにするには、/etc/postfix/main.cf を以下のように変更してください:

myhostname = localhost
mydomain = localdomain
mydestination = $myhostname, localhost.$mydomain, localhost
inet_interfaces = $myhostname, localhost
mynetworks_style = host
default_transport = error: outside mail is not deliverable

他の設定を変更する必要はありません。上記のように設定したら、エイリアスを設定して Postfix を起動してください。

バーチャルメール

バーチャルメールはユーザーアカウントにマッピングされないメールです (/etc/passwd)。

セットアップする方法は仮想ユーザーメールシステムを見てください。

DNS レコード

メールホストを MX レコードに設定する必要があります。通常はドメインプロバイダの設定インターフェイスから設定できます。

メール交換レコード (MX レコード) は Domain Name System におけるリソースレコードの一つで、受取人のドメインを代表してメールメッセージを受け取るメールサーバーを指定します。

メールメッセージがインターネットから送られると、メール転送エージェントが Domain Name System から受取人のドメイン名の MX レコードを聞き出します。このクエリに対して、メール交換サーバーのホスト名のリストが返ってきます。次に、エージェントはそれらのサーバーのどれか一つと (設定番号が一番若いサーバーから順番に) SMTP 接続を確立して、接続が出来た最初のサーバーにメールを配送します。

ノート: Some mail servers will not deliver mail to you if your MX record points to a CNAME. For best results, always point an MX record to an A record definition. For more information, see e.g. Wikipedia's List of DNS Record Types.

設定のチェック

postfix check コマンドを実行してください。設定ファイルで間違っている部分が出力されます。

全ての設定を確認したいときは、postconf と入力します。デフォルト設定との差異点を確認したいときは、postconf -n を実行してみてください。

Postfix の起動

ノート: エイリアスを全く設定していない場合でも Postfix を起動するには最低でも1回は newaliases を実行する必要があります。

postfix.service起動・有効化してください。

テスト

Postfix がテストユーザーにメールを配達できるかどうか確認してみましょう:

nc servername 25
helo testmail.org
mail from:<test@testmail.org>
rcpt to:<cactus@virtualdomain.tld>
data
This is a test email.
.
quit

エラーレスポンス

451 4.3.0 <lisi@test.com>:Temporary lookup failure

MySQL のユーザー名やパスワードが間違っているか、あるいは MySQL のソケットが正しい場所に存在しません。

Postfix を起動する前に newaliases を実行していなかった場合も上記のエラーが発生します。Postfix をローカルのみで使用するのであれば MySQL は不要です。

550 5.1.1 <email@spam.me>: Recipient address rejected: User unknown in virtual mailbox table.

mysql_virtual_mailboxes.cf の中身や main.cfmydestination をチェックしてください。

メールを受け取ったことを確認

$ find /home/vmailer と入力してください。

以下のように表示されるはずです:

/home/vmailer/virtualdomain.tld/cactus@virtualdomain.tld
/home/vmailer/virtualdomain.tld/cactus@virtualdomain.tld/tmp
/home/vmailer/virtualdomain.tld/cactus@virtualdomain.tld/cur
/home/vmailer/virtualdomain.tld/cactus@virtualdomain.tld/new
/home/vmailer/virtualdomain.tld/cactus@virtualdomain.tld/new/1102974226.2704_0.bonk.testmail.org

最後のエントリが実際のメールです。これで動作していることが確認できます。

Tips and tricks

PostfixAdmin

PostfixAdmin を使うには、Apache HTTP Server に書かれているように Apache/MySQL/PHP のセットアップが必要です。

IMAP を機能させるには、php-imap をインストールして /etc/php/php.iniimap.so をアンコメントしてください。

そして、postfixadminインストールしてください。

PostfixAdmin の設定ファイルを編集:

/etc/webapps/postfixadmin/config.inc.php
$CONF['configured'] = true;
// correspond to dovecot maildir path /home/vmail/%d/%u 
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix_user';
$CONF['database_password'] = 'hunter2';
$CONF['database_name'] = 'postfix_db';

// globally change all instances of ''change-this-to-your.domain.tld'' 
// to an appropriate value

If installing dovecot and you changed the password scheme in dovecot (to SHA512-CRYPT for example), reflect that with postfix

/etc/webapps/postfixadmin/config.inc.php
$CONF['encrypt'] = 'dovecot:SHA512-CRYPT';

As of dovecot 2, dovecotpw has been deprecated. You will also want to ensure that your config reflects the new binary name.

/etc/webapps/postfixadmin/config.inc.php
$CONF['dovecotpw'] = "/usr/sbin/doveadm pw";

Create the Apache configuration file:

/etc/httpd/conf/extra/httpd-postfixadmin.conf
Alias /postfixadmin "/usr/share/webapps/postfixAdmin"
<Directory "/usr/share/webapps/postfixAdmin">
    DirectoryIndex index.html index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>

To only allow localhost access to postfixadmin (for heightened security), add this to the previous <Directory> directive:

   Order Deny,Allow
   Deny from all
   Allow from 127.0.0.1

Now, include httpd-postfixadmin.conf to /etc/httpd/conf/httpd.conf:

# PostfixAdmin configuration
Include conf/extra/httpd-postfixadmin.conf
ノート: If you go to yourdomain/postfixadmin/setup.php and it says do not find config.inc.php, add /etc/webapps/postfixadmin to the open_basedir line in /etc/php/php.ini.
ノート: If you get a blank page check the syntax of the file with php -l /etc/webapps/postfixadmin/config.inc.php.

Secure SMTP

詳しくは Postfix TLS Support を見てください。

STARTTLS over SMTP (ポート 587)

To enable STARTTLS over SMTP (port 587, the proper way of securing SMTP), add the following lines to main.cf

/etc/postfix/main.cf
smtpd_tls_security_level = may
smtpd_tls_cert_file = /path/to/cert.pem
smtpd_tls_key_file = /path/to/key.pem

Also in master.cf find and remove the comment from the following line to enable the service on that port:

/etc/postfix/master.cf
submission inet n       -       n       -       -       smtpd

If you need support for the deprecated SMTPS port 465, read the next section.

SMTPS (ポート 465)

The deprecated method of securing SMTP is using the wrapper mode which uses the system service smtps as a non-standard service and runs on port 465.

To enable it uncomment the following lines in

/etc/postfix/master.cf
smtps     inet  n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes

And verify that these lines are in /etc/services:

smtps 465/tcp # Secure SMTP
smtps 465/udp # Secure SMTP

If they are not there, go ahead and add them (replace the other listing for port 465). Otherwise Postfix will not start and you will get the following error:

postfix/master[5309]: fatal: 0.0.0.0:smtps: Servname not supported for ai_socktype

SpamAssassin

spamassassin パッケージをインストールしてください。

/etc/mail/spamassassin/local.cf を開いて必要に応じて設定して下さい。

SpamAssassin のルールの更新

SpamAssassin のマッチパターンを更新してコンパイル:

# sa-update
# sa-compile

上記のコマンドを定期的に実行したい場合、Systemd/タイマーを使用するのが良いでしょう。

以下のサービスを作成してください:

/etc/systemd/system/spamassassin-update.service
[Unit]
Description=spamassassin housekeeping stuff

[Service]
User=spamd
Group=spamd
Type=oneshot
ExecStart=-/usr/bin/vendor_perl/sa-update --allowplugins #You can remove the allowplugins options if you do not want direct plugin updates from SA.
ExecStart=-/usr/bin/vendor_perl/sa-compile
# You can automatically train SA's bayes filter by uncommenting this line and specifying the path to a mailbox where you store email that is spam (for ex this could be yours or your users manually reported spam)
#ExecStart=-/usr/bin/vendor_perl/sa-learn --spam <path to your spam>

そして、上記のサービスを毎日実行するタイマーを作成してください:

/etc/systemd/system/spamassassin-update.timer
[Unit]
Description=spamassassin house keeping

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Finally, you'll need to modify your Spamassassin systemd service file so that it knows to restart itself to read the new rules. Copy the bundled service file to a custom service file:

# cp /usr/lib/systemd/system/spamassassin.service /etc/systemd/system

And edit the newly created /etc/systemd/system/spamassassin.service to include:

[Unit]
PartOf=spamassassin-update.service

This will ensure that Spamassassin's spamd is restarted just before the timer runs. This means the rules will be available the next day if your timer runs daily. This is so that there is no long service interruption while sa.service runs as it takes a while to compile rules.

そして spamassassin-update.service起動有効化してください。

SpamAssassin のスタンドアロン設定

ノート: If you want to combine SpamAssassin and Dovecot Mail Filtering, ignore the next two lines and continue further down instead.

/etc/postfix/master.cf を編集して smtp の下にコンテンツ・フィルタを追加:

smtp      inet  n       -       n       -       -       smtpd
  -o content_filter=spamassassin

以下の SpamAssassin のサービスエントリも追加:

spamassassin unix -     n       n       -       -       pipe
  flags=R user=spamd argv=/usr/bin/vendor_perl/spamc -e /usr/bin/sendmail -oi -f ${sender} ${recipient}

上記の設定をしたら spamassassin.service起動できます。

SpamAssassin と Dovecot LDA / Sieve を組み合わせる (メールフィルタリング)

Dovecot#Sieve に書かれているように LDA と Sieve-Plugin をセットアップします。ただし最後の行 mailbox_command... は無視してください。

代わりに /etc/postfix/master.cf にパイプを追加:

dovecot   unix  -       n       n       -       -       pipe
      flags=DRhu user=vmail:vmail argv=/usr/bin/vendor_perl/spamc -u spamd -e /usr/lib/dovecot/dovecot-lda -f ${sender} -d ${recipient}

そして /etc/postfix/main.cf で有効化:

virtual_transport = dovecot

SpamAssassin と Dovecot LMTP / Sieve を組み合わせる

Dovecot#Sieve に書かれているように LMTP と Sieve をセットアップします。

/etc/dovecot/conf.d/90-plugins.conf を編集して以下を追加:

sieve_before = /etc/dovecot/sieve.before.d/
sieve_extensions = +vnd.dovecot.filter
sieve_plugins = sieve_extprograms
sieve_filter_bin_dir = /etc/dovecot/sieve-filter
sieve_filter_exec_timeout = 120s #this is often needed for the long running spamassassin scans, default is otherwise 10s

ディレクトリを作成:

# mkdir /etc/dovecot/sieve.d/

新しいファイル /etc/dovecot/sieve.before.d/spamassassin.sieve を以下の内容で作成:

require [ "vnd.dovecot.filter" ];
filter "spamc" [ "-d", "127.0.0.1', "--no-safe-fallback" ];

sieve ルール spamassassin.svbin をコンパイル:

# cd /etc/dovecot/sieve.before.d
# sievec spamassassin.sieve

最後に、dovecot.service再起動してください。

SpamAssassin から ClamAV を実行

ClamAV に書かれているように clamd をインストール・設定してください。

上記の設定のどれかにしたがってメールシステムから SpamAssassin が呼び出されるようにしてください。

perl-cpanplus-dist-arch パッケージをインストールして、以下のように ClamAV の perl ライブラリをインストールしてください:

# /usr/bin/vendor_perl/cpanp -i File::Scan::ClamAV
 

http://wiki.apache.org/spamassassin/ClamAVPlugin から2つのファイルを /etc/mail/spamassassin/ に追加してください。/etc/mail/spamassassin/clamav.pm を編集して $CLAM_SOCK で clamd のソケットを指定してください (デフォルトでは /var/lib/clamav/clamd.sock です)。

最後に、spamassassin.service再起動してください。

Razor を使う

先に SpamAssassin をインストールしてから、razor パッケージをインストールしてください。

Razor の登録:

# mkdir /etc/mail/spamassassin/razor
# chown spamd:spamd /etc/mail/spamassassin/razor
# sudo -u spamd -s
$ razor-admin -home=/etc/mail/spamassassin/razor -register
$ razor-admin -home=/etc/mail/spamassassin/razor -create
$ razor-admin -home=/etc/mail/spamassassin/razor -discover

/etc/mail/spamassassin/local.cf に以下を追加:

razor_config /etc/mail/spamassassin/razor/razor-agent.conf

/etc/mail/spamassassin/razor/razor-agent.conf に以下を追加:

razorhome = /etc/mail/spamassassin/razor/

最後に、spamassassin.service再起動してください。

送信者の IP とユーザーエージェントを Received ヘッダに載せない

This is a privacy concern mostly, if you use Thunderbird and send an email. The received header will contain your LAN and WAN IP and info about the email client you used. (Original source: AskUbuntu) What we want to do is remove the Received header from outgoing emails. This can be done by the following steps:

Add this line to main.cf

smtp_header_checks = regexp:/etc/postfix/smtp_header_checks

Create /etc/postfix/smtp_header_checks with this content:

/^Received: .*/     IGNORE
/^User-Agent: .*/   IGNORE

Finally, restart postfix.service

ルールベースのメール処理

ポリシーサービスを使うことで Postfix のメール処理を簡単に設定できます。postfwdpolicydAUR はそのようなポリシーサービスを提供して、SPF のポリシーチェックに加えて送信者や受信者のグレイリスト・ブラックリストを簡単に作ることができます。

ポリシーサービスはスタンドアロンなサービスであり、以下のようにして Postfix に接続します:

/etc/postfix/main.cf
smtpd_recipient_restrictions =
  ...
  check_policy_service unix:/run/policyd.sock
  check_policy_service inet:127.0.0.1:10040

最後にポリシーサービスを配置することで正当なメールだけでが処理されるようになり、負担が減ります。受信されたメッセージ全てが通るように permit ステートメントよりも前に配置してください。

DANE (DNSSEC)

リソースレコード

警告: This is not a trivial section. Be aware that you make sure you know what you are doing. You better read Common Mistakes before.

DANE は複数のタイプのレコードをサポートしていますが、全てが Postfix で使われるわけではありません。

Certificate Usage Field の0はサポートされておらず、1は3にマッピングされていて、2はオプションです。したがって "3" レコードを使用することが推奨されます。詳しくは DANE#リソースレコードを見てください。

設定

Opportunistic DANE is configured this way:

/etc/postfix/main.cf
smtpd_use_tls = yes
smtp_dns_support_level = dnssec
smtp_tls_security_level = dane
/etc/postfix/master.cf
dane       unix  -       -       n       -       -       smtp
  -o smtp_dns_support_level=dnssec
  -o smtp_tls_security_level=dane

To use per-domain policies, e.g. opportunistic DANE for example.org and mandatory DANE for example.com, use something like this:

/etc/postfix/main.cf
indexed = ${default_database_type}:${config_directory}/

# Per-destination TLS policy
#
smtp_tls_policy_maps = ${indexed}tls_policy

# default_transport = smtp, but some destinations are special:
#
transport_maps = ${indexed}transport
transport
example.com dane
example.org dane
tls_policy
example.com dane-only
ノート: For global mandatory DANE, change smtp_tls_security_level to dane-only. Be aware that this makes postfix tempfail on all delivieres that do not use DANE at all!

Full documentation is found here.

参照