Postfix インストール手順

Postfixのインストール

 

インストール

環境: Debian 11.1.0 Postfix asl2-bin amd64 2.1.27+dfsg-2.1+deb11u1   postfix amd64 3.5.13-0+deb11u1

参照したサイト https://www.server-world.info/query?os=Debian_11&p=mail&f=1

バイナリーパッケージのインストール #apt -y install postfix sasl2-bin

Postfix Configuration はNo Configuration を選択

参考にしたサイト:

Build Email Server From Scratch on Debian – Basic Postfix Setup 

 

Tips
  • Postfixのパラメーター myorigin について

From: ドメイン名は、myhostname パラメータではなく、Postfix の myorigin パラメータ (別名システム メール名) によって決定されます。

 

  • TelnetでTCPポート25(outbound)がブロックされてるか確認

sudo apt install telnet

sudo apt install telnet
telnet gmail-smtp-in.l.google.com 25
(Type in quit and press Enter to close the connection)

 

  • Postfixで必要になる主なTCPポートは

sudo ufw allow 25,80,110,143,443,587,465,143,993,995/tcp

 

  • TCPポートスキャン

https://www.ipvoid.com/port-scan/

 

  • Postfix のバージョン確認(postconfコマンド)

$ sudo postconf | grep mail_version
mail_version = 3.5.13
milter_macro_v = $mail_name $mail_version

 

  • Postfixのデフォルトサイズの値確認(postconfコマンド)

$ sudo postconf | grep size_limit
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
mailbox_size_limit = 51200000
message_size_limit = 10240000

 

  • postfix[2199]: fatal: bad string length 0 < 1: html_directory = のエラー

main.cf で html_directory = no

 

  • dovecotでユーザ認証ができない場合

デフォルトがユーザーID500 以上です。/etc/dovecot/conf.d/10-mail.confにて確認しましょう。

# Valid UID range for users, defaults to 500 and above. 
# be done even if first_valid_uid is set to 0.
first_valid_uid = 600
#last_valid_uid = 0

dovecotのステータスの確認  sudo journalctl -eu dovecot

ログの確認 /var/log/mail.log

ログにも記録がない場合はdovecotのジャーナルを確認  sudo journalctl -eu dovecot

 

  • dovecotでメールボックスを使えるユーザ一覧表示

sudo doveadm user '*'

 

  • dovecotを自動的にリスタートさせる

新規にディレクトリを作成 sudo mkdir -p /etc/systemd/system/dovecot.service.d/

以下のリスタート設定ファイルを作成(dovecotが停止後5秒後に自動的にdovecotを再起動)

sudo nano /etc/systemd/system/dovecot.service.d/restart.conf
[Service]
Restart=always
RestartSec=5s

デーモンを再起動 sudo systemctl daemon-reload

動作検証 dovecotを強制停止 sudo pkill dovecot  その後ステータス確認 systemctl status dovecot

 

  • 電子メールとSMTPサーバーの設定を確認

email checker で確認します。 https://network-tools.com/email-tests/

 

  • Virtualドメインの設定

/etc/postfix/main.cf に以下の行を追加

virtual_alias_maps = hash:/etc/postfix/virtual

mydomain  mydestination に指定したドメインを virtual_alias_domains に含めない、メール配送先ユーザーアカウントが存在することが条件です。

/etc/postfix/virtual に以下の内容を記載
# Virtual Domains
hogehoge.jp     virtual
# Virtual alias
noreplay@hogehoge.jp      user1
webmaster@hogehoge.jp    user2

# postmap /etc/postfix/virtual

ハッシュ化された中身を見る場合は  # strings /etc/postfix/virtual.db

 

  • Apacheのデフォルトドメインを停止する(仮想ドメインを使う場合)

他の仮想ホストに干渉する可能性があるため、デフォルトの仮想ホストを無効にします。

sudo a2dissite 000-default.conf

 

  • CertbotコマンドでLetsencryptの証明書を取得(Apacheの場合)

$ sudo certbot certonly -a apache --agree-tos --no-eff-email --staple-ocsp --email 名前@gmail.com -d mail.ドメイン名.biz
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Account registered.
Requesting a certificate for mail.ドメイン名.biz
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mail.ドメイン名.biz/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/mail.ドメイン名.biz/privkey.pem

  • CertbotコマンドでLetsencryptの証明書を取得(Nginxの場合)

$ sudo certbot certonly -a nginx --agree-tos --no-eff-email --staple-ocsp --email 名前@gmail.com -d mail.ドメイン名.biz
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Account registered.
Requesting a certificate for mail.ドメイン名.biz
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mail.ドメイン名.biz/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/mail.ドメイン名.biz/privkey.pem

 

  • Certbotの証明書再発行を自動化

crontabに毎日certbot renew を実行し、postfixとdovecot を再起動、Apacheの場合

sudo crontab -e
@daily certbot renew --quiet && systemctl reload postfix dovecot apache2

Nginxの場合

sudo crontab -e
@daily certbot renew --quiet && systemctl reload postfix dovecot nginx

 

  • PostfixとDovecotで複数のドメインの証明書を設定

一つのTLS証明書で複数のドメインの証明書をまとめる場合

TLS証明書を取得 Apacheの場合

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp -d mail.ドメイン1.com,mail.ドメイン2.com --cert-name mail.ドメイン1.com --email you@example.com

TLS証明書を取得 Nginxの場合

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp -d mail.ドメイン1.com,mail.ドメイン2.com --cert-name mail.ドメイン1.com --email you@example.com

Certbotで既存の証明書を更新して新しいドメインを含めるかどうかを尋ねられたら、U (Update)と答えて Enter キーを押します。

※ 上記のコマンドでは、最初のメール ドメイン1を使用して証明書名を指定したことに注意してください。これはファイル パスで使用されるため、Postfix または Dovecot 構成ファイルでファイル パスを変更する必要はありません。

sudo systemctl reload apache2
sudo systemctl reload nginx 
sudo systemctl reload postfix dovecot

 

各ドメインごとでTLS証明書を取得して設定する場合(複数のTLS証明書)

この設定はまだ動作未検証です!

次のコマンドを使用するだけで、2 番目のメール ドメイン用の別の TLS 証明書を取得できます。

Apacheの場合 sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp -d mail.ドメイン2.com

Nginxの場合 sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp -d mail.ドメイン2.com

1. Postfixの設定(Postfixバージョン3.4以上)

sudo nano /etc/postfix/main.cf

最後に以下の行を追加

tls_server_sni_maps = hash:/etc/postfix/sni_maps

sudo nano /etc/postfix/sni_maps

mail.ドメイン1.com   /etc/letsencrypt/live/mail.ドメイン1.com/privkey.pem    /etc/letsencrypt/live/mail.ドメイン1.com/fullchain.pem
mail.ドメイン2.com   /etc/letsencrypt/live/mail.ドメイン2.com/privkey.pem     /etc/letsencrypt/live/mail.ドメイン2.com/fullchain.pem

※ 最初のドメインの証明書が /etc/postfix/main.cf ファイルで既に使用されている場合は、それを sni_maps ファイルに再度含める必要はありません。

sudo postmap -F /etc/postfix/sni_maps

sudo systemctl restart postfix

2. Dovecotの設定

sudo nano /etc/dovecot/conf.d/10-ssl.conf

既存の以下の行を変更します。

ssl_cert =</etc/letsencrypt/live/mail.ドメイン1.com/fullchain.pem 
ssl_key =</etc/letsencrypt/live/mail.ドメイン1.com/privkey.pem

次のように変更します。

local_name mail.ドメイン1.com {
ssl_cert =</etc/letsencrypt/live/mail.ドメイン1.com/fullchain.pem
ssl_key =</etc/letsencrypt/live/mail.ドメイン1.com/privkey.pem
}
local_name mail.ドメイン2.com {
ssl_cert =</etc/letsencrypt/live/mail.ドメイン2.com/fullchain.pem
ssl_key =</etc/letsencrypt/live/mail.ドメイン2.com/privkey.pem
}

sudo systemctl restart dovecot

 

  • マイクロソフト社のOutlookをメールソフトとして使う場合のSMTPサブミッションサービスの設定(master.cf)

一般的な設定とOutlook用を追加します。 sudo vim /etc/postfix/master.cf

一般的な設定

submission     inet     n    -    y    -    -    smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_tls_wrappermode=no
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth

Outlook用の設定

smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth

 

  • メールサイズとメールボックス容量の設定

message_size_limit = 20480000
メッセージサイズを20MBに変更
mailbox_size_limit = 0
メールボックス容量を無制限に。message_size_limit を変更する場合、mailbox_size_limit を超えないようにしないといけない。
message_size_limit が mailbox_size_limit より大きい場合、メールが一切受信できなくなる。
mailbox_size_limit のデフォルトは51200000(50MB)。

 

 

 

タグ: 

オープンソースソフトウェア: 

Mailman

Mailman3

 

インストール

環境: Debian11 Postfix MariaDB Postfixadmin Apache Mailman3(3.3.3-1)

install :  sudo apt install mailman3-full

インストール写真1

インストール写真2

インストール写真3

インストール写真4

インストール後の設定:

/etc/postfix/main.cf に以下の設定を最後の行に追加します。

# Mailman related settings
owner_request_special = no
transport_maps = hash:/var/lib/mailman3/data/postfix_lmtp
local_recipient_maps = proxy:unix:passwd.byname $alias_maps hash:/var/lib/mailman3/data/postfix_lmtp
relay_domains = ${{$compatibility_level} < {2} ? {$mydestination} : {}} hash:/var/lib/mailman3/data/postfix_domains

 

サイトオーナーのメールアドレスを設定します。 /etc/mailman3/mailman.cfg

site_owner: changeme@example.com ー> 自分のメールアドレスに変更

 

apache2のproxy_uwsgiを有効にします。

sudo a2enmod proxy_uwsgi
sudo systemctl restart apache2

もし、/etc/apache2/conf-enabled/mailman3-web.confというapacheのシンボリックリンクができていなければ、新規作成する。

ln -s /etc/mailman3/apache.conf /etc/apache2/conf-enabled/mailman3-web.conf

/etc/mailman3/apache.confの編集、以下の行の最後の /  を削除する

ProxyPass /mailman3 unix:/run/mailman3-web/uwsgi.sock|uwsgi://localhost

 

 

インストール後の設定

super user のadminアカウントでログインして、そのadminアカウントの登録したメールアドレスへ確認のメールを送信して、本人確認のサイトリンクをクリックして、承認状態になります。Mailmanインストール後に、このadminの登録確認が最初に必要です。

 

メーリングリストの作成

 

Mass operationsの設定

登録するメールアドレスは、以下のような形式で登録します。
 John Doe <jdoe@example.com>
 "John Doe" <jdoe@example.com>
 jdoe@example.com (John Doe)

※Mailman3(3.3.3-1)ではこのMass operations で「Pre Verified」で配信した場合は、最初のWelcomeメッセージは届きましたが、メーリングリストへ投稿できませんでした。機能していないように思います。Mass operationsのデフォルト設定で運用してみます。

 

テンプレートの修正

標準が英語のテンプレートなので、よく使うテンプレートを日本語化します。テンプレートの概要はこのページにて確認できます。https://rohhie.net/ubuntu20-04-building-a-multi-domain-mailing-list-with... 

  • 会員がメーリングリストの登録を解除する際に送られる通知

 [list:user:notice:goodbye]

  • メンバーがメーリングリストに登録されたときに送られる通知

 [list:user:notice:welcome]

  • 購読者がリストに招待されたときに送られるメッセージ

 [list:user:action:invite]

  • 会員がメーリングリストの登録を解除する際に送られる通知

 [list:user:notice:goodbye]

  • 購読確認が必要な場合に購読者に送られるメッセージ

 [list:user:action:subscribe]

 

 

 

FAQ
  • Q:メーリングリストを作成すると公開状態になるので、非公開にしたい。

 A:作成したメーリングリストで、「設定」ー>「List Identity」ー>「Show list on index page」ー>「No」をチェックします。アーカイブは「設定」ー>「Archiving」ー>「Private archives」もしくは「Do not archive this list」を選択します。

  • Q:Mailman3の再起動は

 A: systemctl restart mailman3 と systemctl restart mailman3-web

 

タグ: 

オープンソースソフトウェア: 

PostfixAdmin

PostfixAdminについて

概要 

オープンソース(GPL-2.0)のWebベースのPostfixメールサーバー向け仮想ユーザー管理インタフェースです。

開発コミュニティ: https://github.com/postfixadmin/postfixadmin

 

インストール

参考:Debian 11、Apacheでのインストール https://www.rosehosting.com/blog/how-to-set-up-a-mail-server-with-postfi...

Debian 11、Nginxでのインストール https://www.linuxbabe.com/mail-server/postfixadmin-create-virtual-mailbo...

 

アップデート

Postfixadmin 3.3.11 から 3.3.13へアップデート

ダウンロード 3.3.13  wget https://github.com/postfixadmin/postfixadmin/archive/refs/tags/postfixad...

現在の3.3.11の /var/www/postfixadmin ディレクトリを丸ごと名前を変更して保存

解凍後、/var/www/postfixadmin へ入れ替えます

templates_c を3.3.11のバックアップからコピーして /var/www/postfixadmin/templates_c へ保存

config.local.php を3.3.11のバックアップからコピーして /var/www/postfixadmin/config.local.php へ保存

config.inc.php を編集して、バージョンを修正します $CONF['version'] = '3.3.11'; ---> $CONF['version'] = '3.3.13';

 

 

タグ: 

オープンソースソフトウェア: 

PostfixでのSPF、DKIM、DMARCの設定

PostfixでのSPF、DKIM、DMARC

 

SPF

 

 

FAQ

Q: digやnslookupコマンドでSPF設定内容を確認する方法

A: digコマンドの場合 dig ドメイン名 tx

A: nslookupコマンドの場合  nelookup ドメイン名 txt

 

 

 

DKIM

 

作成したDKIMのドメインキーをDebian11のbind9に設定する場合は、以下のようなドメインキーを表示させ、そのまま、bind9のゾーン設定ファイルに張り付けてBind9再起動で設定されます。コメントは削除しますが、キーのところはそのままのフォーマットでOKです。 その貼り付けを間違えるとBind9の文法エラーになります。

sudo cat /etc/opendkim/keys/ドメイン名/default.txt
default._domainkey      IN      TXT     ( "v=DKIM1; h=sha256; k=rsa; "
          "p=MIIBIjANBgkqhkiG9w0BAQEXXXXXAQ8AMIIBCgKCAQEAvaotoiwmXASZTXXXXXFf1y3H0DCWmnA45vz8oAffQmPrU2YSEOzyKVKLF0g4fPMi7fxsDue+CHCBdUZerzxx4esU8x8SLn9KBb9az3TJf5FeirwJMatBe/DQP5NEUA25tnusyNG9dXXXXXtSoE9aexe/5YPLl7yzblj5fFB8B5fY8LakjfnSVBlULjr0qzottr7RbavlupEhK3"
          "zZSQT2/2SdV3KgybPWSxwgweZpxcv5XXXXXRIr+S7zUh0mTFmFWwE4W7Sx5vuHcN1Wtn9A3roM/7Y0IzgZFDAExC7KkiQq9ByCgW6lMWkPSKIkrTW2sIlAOzz8myV91DINF4/IbQIDAQAB" )  ; ----- DKIM key default for ドメイン名

 

 

FAQ

Q: digやnslookupコマンドでDKIM設定内容を確認する方法

A: digコマンドの場合 dig selector._domainkey.ドメイン名 txt

A: nslookupコマンドの場合  nslookup selector._domainkey.ドメイン名 txt

 

 

 

DMARC

 

FAQ

Q: digやnslookupコマンドでDMARC設定内容を確認する方法

A: digコマンドの場合 dig _dmarc.ドメイン名 txt

A: nslookupコマンドの場合  nelookup _dmarc.ドメイン名 txt

タグ: 

オープンソースソフトウェア: