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 使用者發送電子郵件。

有沒有辦法強制所有出站電子郵件(包括本地發送)通過中繼,但仍接受同一網域的入站電子郵件?昨天我一直在碰壁,我能想到的唯一真正的解決方案是運行兩個單獨的 Postfix 實例 - 一個中繼所有內容,另一個僅用於傳入郵件。但肯定有一種方法可以只用一個實例來做到這一點嗎?我已經搜索過,但似乎到處都假設您只是轉發電子郵件而不執行其他操作。

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.com從清單中設定和刪除 example.com mydestinations,這會使 Office 365 的投遞工作正常,但隨後會破壞舊系統。

我研究過嘗試transport_maps透過中繼發送特定電子郵件地址的所有電子郵件(即移至 Office 365 的電子郵件),其他所有內容都在本地運行,但其中的值似乎總是被忽略。

我完全沒有想法,所以如果有人有任何想法,我將不勝感激。

答案1

好吧,我對此不太滿意,但我成功了。我覺得有一個更直接的方法,但我無法弄清楚。

經過進一步研究,我發現virtual_alias_maps運行中的任何內容transport_maps,這就是為什麼我認為它被忽略了。因此,如果您的地址被重寫,那麼虛擬別名重寫的任何輸出都需要與您要輸入的內容相符transport_maps。然後我的transport_maps哈希看起來像這樣:

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

這將導致電子郵件發送至[電子郵件受保護]轉發到 Office 365,但其他所有內容都在本地交付。

它有效,但我仍然覺得有更好的方法來處理這個問題。

相關內容