Postfix と Office 365: すべての送信メール(ローカルを含む)を中継し、受信メールを配信します

Postfix と Office 365: すべての送信メール(ローカルを含む)を中継し、受信メールを配信します

当社では、一度に少数のユーザーを有効にすることを目標に、Postfix/Dovecot から Office 365 に徐々に移行しています。当社のドメインのメールは Office 365 に届き、Office 365 内で一致するアドレスが見つからない場合は、Postfix に転送され、そこから Dovecot メールボックスに配信されます (当社では仮想ユーザー設定を使用しており、すべてのユーザーは別の LDAP サーバーに保存されています)。これにより、設定されているユーザーには Office 365 を使用できますが、設定されていないユーザーの場合は、メールは既存の Postfix/Dovecot システムに送信されます。

私はフォローしましたこれらの指示コネクタの作成などについては、うまくいきました。EOP IP をホワイトリストに登録した後、Office 365 は Postfix に正常に配信します。問題は、物事が逆方向に進むようにすることです。すべての送信メールは Office 365 を介してリレーされる必要があり、変数を設定してrelayhostローカル ドメインを削除するmydestinationsと、これは機能しますが、Postfix は受信メールを配信しません (バウンス ループが発生します)。ドメインを残しておくとmydestinations、メールはローカルに配信され、リレーを経由しません。つまり、Postfix システム上に残っているユーザーは、Office 365 ユーザーにメールを送信できません。

すべての送信メール (ローカル配信を含む) をリレー経由で送信しながら、同じドメインの受信メールを受け入れるようにする方法はありますか? 昨日からずっと壁にぶつかっていて、私が考えられる唯一の現実的な解決策は、2 つの別々の Postfix インスタンスを実行することです。1 つはすべてをリレーし、もう 1 つは受信メール専用です。しかし、1 つのインスタンスだけでこれを行う方法は確かにあるのでしょうか? 検索しましたが、どこもメールのリレーのみを行い、他には何も行わないと想定しているようです。

postconf -n は次のようになります (ドメインが example.com に変更されました)。Office 365 のリレーを取得するために行った変更はすべて削除しました。

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
content_filter = smtp-amavis:[127.0.0.1]:10024
dovecot_destination_recipient_limit = 1
inet_interfaces = all
inet_protocols = all
mailbox_command = /usr/lib/dovecot/deliver
mailbox_size_limit = 0
mailbox_transport = dovecot
message_size_limit = 20480000
mydestination = $myhostname, silver.example.com, localhost.example.com, localhost, example.com
myhostname = smtp.example.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24 192.168.10.0/24
myorigin = /etc/mailname
readme_directory = no
receive_override_options = no_address_mappings
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc
recipient_delimiter = +
relayhost =
smtp_tls_note_starttls_offer = yes
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipient_access, check_sender_access hash:/etc/postfix/sender_access, check_sender_access cidr:/etc/postfix/o365, reject_authenticated_sender_login_mismatch, permit_sasl_authenticated, permit_mynetworks, reject_invalid_hostname, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_unauth_pipelining, reject_unauth_destination, reject_rbl_client bl.spamcop.net, reject_rbl_client b.barracudacentral.org, reject_rbl_client zen.spamhaus.org, reject_rbl_client cbl.abuseat.org
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = hash:/etc/postfix/local_senders, ldap:/etc/postfix/ldap_senders.cf
smtpd_tls_CAfile = /etc/ssl/certs/example.com.cabundle
smtpd_tls_cert_file = /etc/ssl/certs/example.com.crt
smtpd_tls_key_file = /etc/ssl/private/example.com.key
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3
smtpd_tls_received_header = yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
virtual_alias_domains = events.example.com
virtual_alias_maps = hash:/etc/postfix/redirect, ldap:/etc/postfix/ldap_virtual_users.cf, ldap:/etc/postfix/ldap_virtual_groups.cf
virtual_transport = dovecot

すべてのメールを中継するには、relayhost = example-com.mail.protection.outlook.comexample.com を設定してリストから削除しますmydestinations。これにより、Office 365 の配信は機能しますが、古いシステムが壊れます。

特定のメール アドレス (Office 365 に移動されたものなど) 宛てのすべてのメールをリレー経由で送信してみることを検討しましたtransport_mapsが、他のすべてはローカルで機能しますが、そこに含まれる値は常に無視されるようです。

まったくアイデアがないので、誰かアイデアがあれば教えていただけるとありがたいです。

答え1

まあ、これで完全に満足というわけではありませんが、うまくいきました。もっと簡単な方法があるような気がしますが、わかりません。

さらに調査してみるとvirtual_alias_maps前にに何もないのでtransport_maps、無視されていると思いました。したがって、アドレスが書き換えられている場合は、仮想エイリアスの書き換えからの出力が、 に入力するものと一致する必要がありますtransport_maps。すると、私のtransport_mapsハッシュは次のようになります。

[email protected]        smtp:example-com.mail.protection.outlook.com
@example.com  :
*       :

これにより、電子メールが[メールアドレス]Office 365 に中継されますが、その他すべてはローカルで配信されます。

うまく機能していますが、これを処理するにはもっと良い方法があるように感じます。

関連情報