Home
%3CLINGO-SUB%20id%3D%22lingo-sub-609238%22%20slang%3D%22en-US%22%3EAdvanced%20Office%20365%20Routing%3A%20Locking%20Down%20Exchange%20On-Premises%20when%20MX%20points%20to%20Office%20365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-609238%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20often%20get%20request%20from%20customers%20to%20control%20mail%20flow%20routing%20in%20a%20hybrid%20deployment%2C%20for%20various%20compliance%20requirements.%20Achieving%20the%20desired%20routing%20greatly%20depends%20on%20where%20the%20MX%20record%20is%20pointed%20to%20and%20the%20involvement%20of%203rd%20party%20mail%20gateways.%20Also%2C%20use%20of%20Centralized%20Mail%20Transport%20and%20the%20two%20mandatory%20Office%20365%20native%20domains%20-%20tenant.onmicrosoft.com%20and%20tenant.mail.onmicrosoft.com%20may%20make%20it%20even%20more%20complex.%20In%20this%20article%2C%20we%20will%20discuss%20the%20scenario%2C%20which%20is%20recommended%20for%20most%20hybrid%20organizations%2C%20where%20MX%20is%20pointed%20to%20EOP%20and%20customer%20wants%20to%20restrict%20their%20on-premises%20Exchange%20servers%20to%20only%20accept%20emails%20from%20their%20own%20Office%20365%20tenant.%20Before%20we%20start%2C%20we%20highly%20recommend%20that%20you%20go%20through%20the%20following%20articles%20to%20understand%20the%20basics%20of%20Hybrid%20mail%20flow%3A%3CUL%3E%0A%20%20%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fexchange%2Ftransport-routing%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ETransport%20routing%20in%20Exchange%20hybrid%20deployments%3C%2FA%3E%3C%2FLI%3E%0A%20%20%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fexchange%2Fmail-flow-best-practices%2Fuse-connectors-to-configure-mail-flow%2Fset-up-connectors-to-route-mail%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESet%20up%20connectors%20to%20route%20mail%20between%20Office%20365%20and%20your%20own%20email%20servers%3C%2FA%3E%3C%2FLI%3E%0A%20%20%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fexchange%2Fmail-flow-best-practices%2Fmanage-mail-flow-for-multiple-locations%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EManage%20mail%20flow%20with%20mailboxes%20in%20multiple%20locations%20(Exchange%20Online%20and%20on-premises)%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow1.jpg%22%20target%3D%22_blank%22%3E%3CIMG%20title%3D%22hybmailflow1%22%20style%3D%22border%3A%200px%20currentcolor%22%20alt%3D%22hybmailflow1%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow1_thumb.jpg%22%20class%3D%22%22%20width%3D%22943%22%20height%3D%22327%22%20border%3D%220%22%20%2F%3E%3C%2FA%3E%20The%20above%20diagram%20shows%20mail%20routing%20for%20contoso.com.%20Their%20MX%20record%20is%20pointed%20to%20Office365.%20This%20means%20on-premises%20Exchange%20servers%20are%20not%20supposed%20to%20receive%20external%20emails%20directly.%20Inbound%20email%20to%20Contoso%E2%80%99s%20On-premises%20servers%20will%20always%20originate%20from%20or%20relay%20through%20their%20Office%20365%20tenant.%20Contoso%20wants%20to%20block%20direct%20email%20delivery%20from%20other%20Office%20365%20tenants%20like%20fabricam.com%20to%20their%20on-premises%20Exchange%20Servers%2C%20because%20that%20would%20bypass%20policies%20and%20rules%20created%20on%20their%20Office%20365%20tenant.%20In%20a%20hybrid%20Setup%2C%20mail%20from%20Exchange%20Online%20will%20be%20received%20by%20the%20on-premises%20Exchange%20server%20either%20by%20the%20Default%20Frontend%20Receive%20Connector%20or%20the%20%E2%80%9CInbound%20from%20Office%20365%E2%80%9D%20receive%20Connector%20created%20by%20hybrid%20configuration%20wizard.%20By%20default%2C%20%E2%80%9CInbound%20from%20Office%20365%E2%80%9D%20Receive%20Connector%20will%20have%20all%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fenterprise%2Furls-and-ip-address-ranges%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EOffice%20365%20IP%20Address%3C%2FA%3E%20ranges%20as%20allowed%20Remote%20IP%20Range.%20Or%2C%20in%20case%20of%20the%20Frontend%20Receive%20connector%2C%20it%20will%20be%20open%20to%20all%20IPs%20(0.0.0.0-255.255.255.255).%20Perhaps%20it%20goes%20without%20saying%2C%20but%20if%20your%20MX%20record%20points%20to%20Office%20365%2C%20you%20definitely%20don%E2%80%99t%20want%20to%20allow%20anonymous%20submissions%20via%20the%20on-premises%20receive%20connector.%20But%20it%E2%80%99s%20not%20as%20simple%20as%20disabling%20anonymous%20permission%20on%20the%20receive%20connector.%20For%20Exchange%202010%20server%2C%20disabling%20anonymous%20permission%20on%20%E2%80%9CInbound%20from%20Office%20365%E2%80%9D%20receive%20connector%20would%20cause%20%E2%80%9C%3CI%3E5.7.1%20Client%20was%20not%20authenticated%E2%80%9D%20%3C%2FI%3ENDR%20for%20emails%20coming%20from%20even%20your%20own%20Tenant.%20Whereas%2C%20for%20Exchange%202013%20onwards%2C%20it%20works%20inversely%2C%20disabling%20anonymous%20permission%20does%20not%20block%20email%20from%20your%20tenant%20and%20for%20that%20matter%2C%20emails%20from%20other%20tenants%20are%20also%20allowed.%20So%2C%20disabling%20anonymous%20permission%20is%20not%20enough%20to%20lock%20down%20the%20on-premises%20Exchange%20server%20to%20only%20accept%20emails%20from%20your%20own%20Office%20365%20tenant.%20%3CEM%3E%20%3C%2FEM%3E%20The%20concern%20with%20this%20configuration%20is%3A%20any%20Office%20365%20tenant%20who%20knows%20external%20hostname%2FIP%20address%20of%20your%20server%20can%20send%20emails%20to%20your%20on-premises%20servers%20directly.%20I%20want%20to%20clarify%20here%20that%20%3CB%3Ealthough%20our%20on-premises%20receive%20connector%20allows%20all%20Exchange%20Online%20IP%20Addresses%20to%20submit%20emails%2C%20mails%20sent%20from%20other%20tenants%20will%20not%20be%20an%20authenticated%20submission%20and%20they%20wouldn%E2%80%99t%20be%20able%20to%20relay%20through%20your%20on-premises%20server%20or%20be%20treated%20as%20internal%20to%20your%20organization%3C%2FB%3E.%20%3CB%3EThe%20emails%20from%20other%20tenants%20will%20have%20the%20X-MS-Exchange-Organization-AuthAs%20header%20set%20to%20%E2%80%9CAnonymous%E2%80%9D%3C%2FB%3E.%20Still%2C%20customers%20might%20want%20to%20go%20further%20than%20this%20to%20restrict%20other%20tenants%20to%20send%20emails%20directly%20to%20their%20on-premises%20environment%20to%20avoid%20various%20compliance%20issues.%20One%20obvious%20example%20is%20that%20you%20may%20have%20DLP%20rules%20configured%20inside%20of%20your%20Office%20365%20tenant%2C%20so%20sending%20email%20directly%20to%20your%20on-premises%20server%20would%20bypass%20that%20rule.%20First%2C%20let%E2%80%99s%20try%20to%20understand%20the%20difference%20between%20the%20situations%20when%20mail%20is%20sent%20from%20your%20own%20tenant%20and%20mail%20is%20sent%20from%20other%20tenants.%20When%20email%20is%20sent%20from%20or%20relayed%20through%20your%20own%20tenant%2C%20Exchange%20Online%20will%20send%20XOORG%20SMTP%20command%20extension%20with%20the%20%E2%80%9CMAIL%20FROM%E2%80%9D%20Command%20which%20will%20be%20same%20as%20the%20default%20accepted%20domain%20on%20Exchange%20Online.%20The%20following%20two%20conditions%20are%20checked%20on%20the%20on-premises%20Server%3A%3COL%3E%0A%20%20%3CLI%3EIf%20the%20Receive%20connector%20TlsDomainCapabilities%20is%20set%20to%20AcceptedCloudServicesMail%2C%20%3CEM%3Eand%3C%2FEM%3E%3C%2FLI%3E%0A%20%20%3CLI%3EIf%20the%20XOORG%20Domain%20mentioned%20with%20MAIL%20FROM%20Command%20matches%20on-premises%20Accepted%20Domain%20or%20matches%20any%20remote%20domains%20with%20TrustedMailInboundEnabled%20set%20to%20true.%3C%2FLI%3E%0A%3C%2FOL%3EIf%20the%20above%20conditions%20are%20true%2C%20on-premises%20server%20will%20treat%20the%20connection%20as%20Authenticated%20and%20will%20promote%20cross%20premises%20headers%20to%20org%20headers.%20The%20protocol%20log%20collected%20from%20on-premises%20server%20for%20an%20email%20received%20from%20Hotmail%20and%20relayed%20through%20Contoso%20tenant%20will%20look%20something%20like%20below-%3C%2FP%3E%3CP%20class%3D%22code%22%3E2018-11-09T16%3A30%3A50.288Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C13%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C%26lt%3B%2CMAIL%20FROM%3A%3CSOMEUSER%3E%20SIZE%3D22396%20AUTH%3D%26lt%3B%26gt%3B%20%3CSPAN%20style%3D%22color%3A%20%23ff0000%22%3EXOORG%3Dcontoso.com%3C%2FSPAN%3E%2C%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.289Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C14%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C*%2CSMTPAcceptAnyRecipient%20SMTPAcceptAuthoritativeDomainSender%20BypassAntiSpam%20BypassMessageSizeLimit%2CGranted%20Mail%20Item%20Permissions%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.289Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C15%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C*%2C08D61A879C5AB8C3%3B2018-11-09T16%3A30%3A48.725Z%3B1%2Creceiving%20message%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.290Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C16%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C%26lt%3B%2CRCPT%20TO%3AJohn%40contoso.com%2C%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.290Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C17%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C%26gt%3B%2C250%202.1.0%20Sender%20OK%2C%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.290Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C18%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C%26gt%3B%2C250%202.1.5%20Recipient%20OK%2C%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.538Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C19%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C%26lt%3B%2CBDAT%2011393%20LAST%2C%3CBR%20%2F%3E2018-11-09T16%3A30%3A50.789Z%2CE161%5CDefault%20Frontend%20E161%2C08D61A879C5AB8C3%2C20%2C192.168.2.52%3A25%2C4.4.0.1%3A29143%2C*%2C%2C%3CSPAN%20style%3D%22color%3A%20%23ff0000%22%3ESet%20mail%20item%20OORG%20to%20'contoso.com'%20based%20on%20'MAIL%20FROM%3A%3C%2FSPAN%3E'%3C%2FSOMEUSER%3E%3C%2FP%3EAlso%2C%20this%20will%20make%20sure%20that%20all%20emails%20directly%20sent%20from%20or%20relayed%20through%20EOP%20have%20the%20%E2%80%9CX-OriginatorOrg%E2%80%9D%20header%20set%20to%20your%20Verified%20Domain%20in%20EXO.%20So%2C%20the%20email%20will%20have%20the%20following%20header%3A%3CP%20class%3D%22code%22%3EX-OriginatorOrg%3A%20contoso.com%3C%2FP%3EAll%20of%20this%20is%20setup%20for%20you%20by%20the%20Hybrid%20Configuration%20Wizard%2C%20and%20as%20long%20as%20Office%20365%20is%20connecting%20directly%20to%20your%20on-premises%20Exchange%20server(s)%2C%20XOORG%20SMTP%20command%20is%20how%20we%20keep%20things%20secure%20%E2%80%93%20you%20only%20trust%20your%20Office%20365%20tenant%2C%20not%20others.%20In%20fact%2C%20because%20the%20XOORG%20command%20is%20only%20understood%20by%20Exchange%2C%20we%20say%20it%20is%20more%20secure%20to%20connect%20Office%20365%20directly%20to%20Exchange%20or%20Exchange%20Edge.%20Other%20application%20layer%20filtering%20devices%2C%20etc.%20do%20not%20understand%20XOORG%2C%20cannot%20pass%20it%2C%20and%20you%20actually%20end%20up%20in%20a%20less%20secure%20state.%20Emails%20directly%20sent%20from%20other%20tenants%20to%20on-premises%20servers%20will%20also%20use%20the%20XOORG%20SMTP%20Extension%20and%20will%20have%20the%20X-OriginatorOrg%20header%2C%20but%20it%20will%20not%20match%20with%20your%20Accepted%20domain%20or%20Remote%20domain%20with%20TrustedMailInboundEnabled.%20They%20are%20still%20allowed%20by%20default%20into%20your%20on-premises%20Exchange%20environment%20because%20we%20must%20allow%20other%20possible%20routing%20configurations.%20Can%20someone%20spoof%20XOORG%3F%20The%20answer%20is%20%E2%80%9Cno%E2%80%9D%2C%20the%20XOORG%20headers%20cannot%20be%20spoofed%20because%20it%20is%20the%20combination%20of%20the%20EOP%20TLS%20certificate%2C%20connector%20setting%20and%20accepted%20domain%20%E2%80%93%20and%20we%20control%20the%20headers%20when%20they%20pass%20through%20us%2C%20which%20is%20the%20case%20when%20our%20certificate%20is%20used.%3CP%20class%3D%22note%22%3ENote%3A%20X-MS-Exchange-Organization-AuthAs%20header%20stamped%20on%20email%20received%20by%20on-premises%20server%20from%20O365%20can%20be%20either%20%E2%80%9CInternal%E2%80%9D%20or%20%E2%80%9CAnonymous%E2%80%9D.%20For%20instance%2C%20emails%20sent%20from%20your%20EXO%20tenant%20to%20on-premises%20servers%2C%20will%20have%20the%20X-MS-Exchange-Organization-AuthAs%20set%20to%20%E2%80%9CInternal%E2%80%9D.%20If%20it%E2%80%99s%20an%20external%20email%20which%20is%20relayed%20through%20your%20tenant%2C%20the%20original%20%E2%80%9CAnonymous%E2%80%9D%20identity%20would%20be%20preserved%20and%20the%20X-MS-Exchange-Organization-AuthAs%20will%20be%20set%20to%20%E2%80%9CAnonymous%E2%80%9D.%20Thus%2C%20X-MS-Exchange-Organization-AuthAs%20header%20would%20not%20differentiate%20between%20email%20coming%20directly%20to%20your%20on-premises%20and%20email%20relayed%20through%20your%20tenant.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1759369785%22%20id%3D%22toc-hId-1760056151%22%3EHow%20to%20make%20sure%20other%20Office%20365%20tenants%20can%E2%80%99t%20bypass%20intended%20routing%3C%2FH2%3ENow%20we%20know%20how%20to%20differentiate%20between%20emails%20from%20your%20own%20tenant%20and%20from%20others.%20XOORG%20validation%20and%20X-OriginatorOrg%20header%20is%20the%20key.%20You%20can%20create%20a%20transport%20rule%20on%20your%20on-premises%20organization%20to%20forward%20these%20messages%20for%20approval%20(if%20X-OriginatorOrg%20header%20is%20not%20stamped%20correctly%2C%20because%20these%20emails%20are%20not%20received%20through%20your%20Office%20365%20tenant).%20Alternately%2C%20you%20can%20generate%20incident%20report%20or%20redirect%20these%20emails%20to%20someone%20else%20for%20investigation.%20This%20way%2C%20you%20will%20know%20if%20there%20are%20valid%20emails%20which%20are%20coming%20directly%20to%20your%20on-premises%20server%20because%20of%20some%20configuration%20issues.%20For%20example%2C%20it%20might%20be%20an%20internal%20application%20sending%20emails%20directly%20on%20your%20in-house%20servers.%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow2.jpg%22%20target%3D%22_blank%22%3E%3CIMG%20title%3D%22hybmailflow2%22%20style%3D%22border%3A%200px%20currentcolor%22%20alt%3D%22hybmailflow2%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow2_thumb.jpg%22%20class%3D%22%22%20width%3D%22685%22%20height%3D%22595%22%20border%3D%220%22%20%2F%3E%3C%2FA%3E%20Once%20you%20identify%20these%20issues%20and%20decide%20if%20you%E2%80%99re%20ready%20to%20take%20more%20drastic%20measures%2C%20you%20can%20tweak%20the%20rule%20to%20reject%20instead%20of%20redirect%20or%20forward%3A%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow3.jpg%22%20target%3D%22_blank%22%3E%3CIMG%20title%3D%22hybmailflow3%22%20style%3D%22border%3A%200px%20currentcolor%22%20alt%3D%22hybmailflow3%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow3_thumb.jpg%22%20class%3D%22%22%20width%3D%22685%22%20height%3D%22556%22%20border%3D%220%22%20%2F%3E%3C%2FA%3E%20Now%20anyone%20who%20tries%20to%20send%20emails%20directly%20to%20your%20on-premises%20server%20bypassing%20your%20MX%20record%20(which%20points%20to%20EOP)%20will%20receive%20the%20following%20non-delivery%20report%3A%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow4.jpg%22%20target%3D%22_blank%22%3E%3CIMG%20title%3D%22hybmailflow4%22%20style%3D%22border%3A%200px%20currentcolor%22%20alt%3D%22hybmailflow4%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow4_thumb.jpg%22%20class%3D%22%22%20width%3D%221046%22%20height%3D%22374%22%20border%3D%220%22%20%2F%3E%3C%2FA%3E%20The%20rule%20will%20function%20similarly%20in%20all%20scenarios%2C%20whether%20centralized%20mail%20transport%20is%20enabled%20or%20not.%20There%20is%20one%20more%20slightly%20different%20routing%20scenario%20which%20we%20want%20to%20cover%20in%20this%20article.%20Imagine%20MX%20for%20contoso.com%20is%20pointed%20to%20a%203rd%20party%20email%20filter%20which%20forwards%20the%20email%20to%20their%20on-premises%20Exchange%20server.%20And%20then%20based%20on%20recipient%E2%80%99s%20mailbox%20location%2C%20it%20can%20either%20be%20delivered%20locally%20or%20forwarded%20to%20Office%20365.%20So%20although%20the%20routing%20is%20different%2C%20we%20have%20a%20very%20similar%20issue%20as%20mentioned%20earlier%2C%20that%20any%20Office%20365%20tenant%20who%20knows%20external%20hostname%2FIP%20address%20of%20your%20server%20can%20send%20emails%20to%20your%20on-premises%20server%20directly.%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow5.jpg%22%20target%3D%22_blank%22%3E%3CIMG%20title%3D%22hybmailflow5%22%20style%3D%22border%3A%200px%20currentcolor%22%20alt%3D%22hybmailflow5%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow5_thumb.jpg%22%20class%3D%22%22%20width%3D%22983%22%20height%3D%22448%22%20border%3D%220%22%20%2F%3E%3C%2FA%3E%20Stopping%20those%20emails%20using%20the%20Transport%20rule%20described%20above%20won%E2%80%99t%20work%20because%20inbound%20emails%20from%20internet%20through%20the%203rd%20party%20device%20won%E2%80%99t%20have%20the%20X-OriginatorOrg%20header%20and%20all%20those%20valid%20emails%20will%20be%20blocked%20too.%20Now%2C%20looking%20at%20the%20above%20diagram%2C%20and%20from%20our%20earlier%20discussion%2C%20we%20can%20make%20following%20assumptions%20for%20an%20inbound%20email%20to%20the%20on-premises%20server%3A%3COL%3E%0A%20%20%3CLI%3EInbound%20email%20from%20internet%20will%20have%20IP%20Address%20of%20the%203%3CSUP%3Erd%3C%2FSUP%3E%20party%20email%20filter%20in%20the%20receive%20header%20if%20it%E2%80%99s%20correctly%20routed%20through%20the%20MX.%3C%2FLI%3E%0A%20%20%3CLI%3EIn%20hybrid%20mail%20flow%2C%20email%20from%20your%20own%20tenant%20contoso.com%20is%20considered%20as%20sent%20from%20%E2%80%9CInside%20the%20organization%E2%80%9D.%3C%2FLI%3E%0A%20%20%3CLI%3EEmail%20from%20other%20tenants%20like%20fabrikam%20will%20be%20treated%20as%20anonymous%20email%20from%20%E2%80%9COutside%20the%20organization%E2%80%9D.%3C%2FLI%3E%0A%3C%2FOL%3ESo%2C%20based%20on%20the%20above%20assumptions%2C%20we%20can%20create%20the%20following%20rule%20to%20block%20email%20which%20is%20sent%20directly%20to%20on-premises%20server%20bypassing%20the%203%3CSUP%3Erd%3C%2FSUP%3E%20party%20filter.%20In%20this%20example%2C%20192.168.2.51%20is%20the%20IP%20address%20of%20your%203%3CSUP%3Erd%3C%2FSUP%3E%20party%20email%20filter.%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow6.jpg%22%20target%3D%22_blank%22%3E%3CIMG%20title%3D%22hybmailflow6%22%20style%3D%22border%3A%200px%20currentcolor%22%20alt%3D%22hybmailflow6%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Flegacyfs%2Fonline%2Fmedia%2F2019%2F02%2Fhybmailflow6_thumb.jpg%22%20class%3D%22%22%20width%3D%22710%22%20height%3D%22614%22%20border%3D%220%22%20%2F%3E%3C%2FA%3E%20We%20hope%20this%20post%20will%20be%20helpful%20in%20planning%20your%20hybrid%20mailflow.%20I%20also%20want%20to%20take%20a%20moment%20and%20thank%20Scott%20Landry%2C%20Daniel%20Talbot%2C%20Lou%20Ma%3CA%3E%3C%2FA%3Endich%20and%20Ramon%20Infante%20for%20their%20contributions.%20%3CSPAN%20class%3D%22author%22%3EArindam%20Thokder%3C%2FSPAN%3E%3C%2FLINGO-BODY%3E

We often get request from customers to control mail flow routing in a hybrid deployment, for various compliance requirements. Achieving the desired routing greatly depends on where the MX record is pointed to and the involvement of 3rd party mail gateways. Also, use of Centralized Mail Transport and the two mandatory Office 365 native domains - tenant.onmicrosoft.com and tenant.mail.onmicrosoft.com may make it even more complex. In this article, we will discuss the scenario, which is recommended for most hybrid organizations, where MX is pointed to EOP and customer wants to restrict their on-premises Exchange servers to only accept emails from their own Office 365 tenant. Before we start, we highly recommend that you go through the following articles to understand the basics of Hybrid mail flow:

hybmailflow1 The above diagram shows mail routing for contoso.com. Their MX record is pointed to Office365. This means on-premises Exchange servers are not supposed to receive external emails directly. Inbound email to Contoso’s On-premises servers will always originate from or relay through their Office 365 tenant. Contoso wants to block direct email delivery from other Office 365 tenants like fabricam.com to their on-premises Exchange Servers, because that would bypass policies and rules created on their Office 365 tenant. In a hybrid Setup, mail from Exchange Online will be received by the on-premises Exchange server either by the Default Frontend Receive Connector or the “Inbound from Office 365” receive Connector created by hybrid configuration wizard. By default, “Inbound from Office 365” Receive Connector will have all Office 365 IP Address ranges as allowed Remote IP Range. Or, in case of the Frontend Receive connector, it will be open to all IPs (0.0.0.0-255.255.255.255). Perhaps it goes without saying, but if your MX record points to Office 365, you definitely don’t want to allow anonymous submissions via the on-premises receive connector. But it’s not as simple as disabling anonymous permission on the receive connector. For Exchange 2010 server, disabling anonymous permission on “Inbound from Office 365” receive connector would cause “5.7.1 Client was not authenticated” NDR for emails coming from even your own Tenant. Whereas, for Exchange 2013 onwards, it works inversely, disabling anonymous permission does not block email from your tenant and for that matter, emails from other tenants are also allowed. So, disabling anonymous permission is not enough to lock down the on-premises Exchange server to only accept emails from your own Office 365 tenant. The concern with this configuration is: any Office 365 tenant who knows external hostname/IP address of your server can send emails to your on-premises servers directly. I want to clarify here that although our on-premises receive connector allows all Exchange Online IP Addresses to submit emails, mails sent from other tenants will not be an authenticated submission and they wouldn’t be able to relay through your on-premises server or be treated as internal to your organization. The emails from other tenants will have the X-MS-Exchange-Organization-AuthAs header set to “Anonymous”. Still, customers might want to go further than this to restrict other tenants to send emails directly to their on-premises environment to avoid various compliance issues. One obvious example is that you may have DLP rules configured inside of your Office 365 tenant, so sending email directly to your on-premises server would bypass that rule. First, let’s try to understand the difference between the situations when mail is sent from your own tenant and mail is sent from other tenants. When email is sent from or relayed through your own tenant, Exchange Online will send XOORG SMTP command extension with the “MAIL FROM” Command which will be same as the default accepted domain on Exchange Online. The following two conditions are checked on the on-premises Server:
  1. If the Receive connector TlsDomainCapabilities is set to AcceptedCloudServicesMail, and
  2. If the XOORG Domain mentioned with MAIL FROM Command matches on-premises Accepted Domain or matches any remote domains with TrustedMailInboundEnabled set to true.
If the above conditions are true, on-premises server will treat the connection as Authenticated and will promote cross premises headers to org headers. The protocol log collected from on-premises server for an email received from Hotmail and relayed through Contoso tenant will look something like below-

2018-11-09T16:30:50.288Z,E161\Default Frontend E161,08D61A879C5AB8C3,13,192.168.2.52:25,4.4.0.1:29143,<,MAIL FROM:<someuser@hotmail.com> SIZE=22396 AUTH=<> XOORG=contoso.com,
2018-11-09T16:30:50.289Z,E161\Default Frontend E161,08D61A879C5AB8C3,14,192.168.2.52:25,4.4.0.1:29143,*,SMTPAcceptAnyRecipient SMTPAcceptAuthoritativeDomainSender BypassAntiSpam BypassMessageSizeLimit,Granted Mail Item Permissions
2018-11-09T16:30:50.289Z,E161\Default Frontend E161,08D61A879C5AB8C3,15,192.168.2.52:25,4.4.0.1:29143,*,08D61A879C5AB8C3;2018-11-09T16:30:48.725Z;1,receiving message
2018-11-09T16:30:50.290Z,E161\Default Frontend E161,08D61A879C5AB8C3,16,192.168.2.52:25,4.4.0.1:29143,<,RCPT TO:John@contoso.com,
2018-11-09T16:30:50.290Z,E161\Default Frontend E161,08D61A879C5AB8C3,17,192.168.2.52:25,4.4.0.1:29143,>,250 2.1.0 Sender OK,
2018-11-09T16:30:50.290Z,E161\Default Frontend E161,08D61A879C5AB8C3,18,192.168.2.52:25,4.4.0.1:29143,>,250 2.1.5 Recipient OK,
2018-11-09T16:30:50.538Z,E161\Default Frontend E161,08D61A879C5AB8C3,19,192.168.2.52:25,4.4.0.1:29143,<,BDAT 11393 LAST,
2018-11-09T16:30:50.789Z,E161\Default Frontend E161,08D61A879C5AB8C3,20,192.168.2.52:25,4.4.0.1:29143,*,,Set mail item OORG to 'contoso.com' based on 'MAIL FROM:'

Also, this will make sure that all emails directly sent from or relayed through EOP have the “X-OriginatorOrg” header set to your Verified Domain in EXO. So, the email will have the following header:

X-OriginatorOrg: contoso.com

All of this is setup for you by the Hybrid Configuration Wizard, and as long as Office 365 is connecting directly to your on-premises Exchange server(s), XOORG SMTP command is how we keep things secure – you only trust your Office 365 tenant, not others. In fact, because the XOORG command is only understood by Exchange, we say it is more secure to connect Office 365 directly to Exchange or Exchange Edge. Other application layer filtering devices, etc. do not understand XOORG, cannot pass it, and you actually end up in a less secure state. Emails directly sent from other tenants to on-premises servers will also use the XOORG SMTP Extension and will have the X-OriginatorOrg header, but it will not match with your Accepted domain or Remote domain with TrustedMailInboundEnabled. They are still allowed by default into your on-premises Exchange environment because we must allow other possible routing configurations. Can someone spoof XOORG? The answer is “no”, the XOORG headers cannot be spoofed because it is the combination of the EOP TLS certificate, connector setting and accepted domain – and we control the headers when they pass through us, which is the case when our certificate is used.

Note: X-MS-Exchange-Organization-AuthAs header stamped on email received by on-premises server from O365 can be either “Internal” or “Anonymous”. For instance, emails sent from your EXO tenant to on-premises servers, will have the X-MS-Exchange-Organization-AuthAs set to “Internal”. If it’s an external email which is relayed through your tenant, the original “Anonymous” identity would be preserved and the X-MS-Exchange-Organization-AuthAs will be set to “Anonymous”. Thus, X-MS-Exchange-Organization-AuthAs header would not differentiate between email coming directly to your on-premises and email relayed through your tenant.

How to make sure other Office 365 tenants can’t bypass intended routing

Now we know how to differentiate between emails from your own tenant and from others. XOORG validation and X-OriginatorOrg header is the key. You can create a transport rule on your on-premises organization to forward these messages for approval (if X-OriginatorOrg header is not stamped correctly, because these emails are not received through your Office 365 tenant). Alternately, you can generate incident report or redirect these emails to someone else for investigation. This way, you will know if there are valid emails which are coming directly to your on-premises server because of some configuration issues. For example, it might be an internal application sending emails directly on your in-house servers. hybmailflow2 Once you identify these issues and decide if you’re ready to take more drastic measures, you can tweak the rule to reject instead of redirect or forward: hybmailflow3 Now anyone who tries to send emails directly to your on-premises server bypassing your MX record (which points to EOP) will receive the following non-delivery report: hybmailflow4 The rule will function similarly in all scenarios, whether centralized mail transport is enabled or not. There is one more slightly different routing scenario which we want to cover in this article. Imagine MX for contoso.com is pointed to a 3rd party email filter which forwards the email to their on-premises Exchange server. And then based on recipient’s mailbox location, it can either be delivered locally or forwarded to Office 365. So although the routing is different, we have a very similar issue as mentioned earlier, that any Office 365 tenant who knows external hostname/IP address of your server can send emails to your on-premises server directly. hybmailflow5 Stopping those emails using the Transport rule described above won’t work because inbound emails from internet through the 3rd party device won’t have the X-OriginatorOrg header and all those valid emails will be blocked too. Now, looking at the above diagram, and from our earlier discussion, we can make following assumptions for an inbound email to the on-premises server:
  1. Inbound email from internet will have IP Address of the 3rd party email filter in the receive header if it’s correctly routed through the MX.
  2. In hybrid mail flow, email from your own tenant contoso.com is considered as sent from “Inside the organization”.
  3. Email from other tenants like fabrikam will be treated as anonymous email from “Outside the organization”.
So, based on the above assumptions, we can create the following rule to block email which is sent directly to on-premises server bypassing the 3rd party filter. In this example, 192.168.2.51 is the IP address of your 3rd party email filter. hybmailflow6 We hope this post will be helpful in planning your hybrid mailflow. I also want to take a moment and thank Scott Landry, Daniel Talbot, Lou Mandich and Ramon Infante for their contributions. Arindam Thokder
8 Comments
Not applicable
For the last scenario, you will need both possible exceptions, correct? The IP address(es) of the mail gateway and the X-OriginatingOrg with your default tenant domain.
Not applicable
Hello Dustin, for the last scenario, we don't need X-OriginatingOrg exception because mail from your own tenant will be considered as from “Inside the organization”. So mail from your tenant will be exempted anyway.
Not applicable
We are in the last scenario, MX records point to on premise 3rd party filtering, then routing through on prem to our ExO tenant (we have centralized mailflow). I can tell you from experience (and a case with support) that just adding the IPs is not enough. You'll need to Exempt 'calendaring' message types (or external messages sent to delegates will be blocked as 'external' when delegation sends it to the delegate on behalf of the 'boss'), and exempt messages with headers 'x-ms-exchange-organization-AuthAs' of 'internal' or internal Out of Office messages will be blocked.
Not applicable
Hello MRI503X, I tested the scenario you explained here, however I am unable to repro this in my lab. I tested few scenarios-

Scenario1-

Meeting is sent from External Domain to a user in tenant1 (say user1). User1 forwarded the Meeting to tenant2 whose MX is pointed to 3rd Party. I see the email is sent to 3rd party itself and not directly to tenant2. So the IP Address of 3rd party will be there in the header and the email won’t be blocked by the rule (because of IP exception)

Scenario2-

Meeting is Sent from External Domain to tenant1 (say user1). User1 on behalf of his manager forward the e-mail to an On-Prem user. Here the Auth-AS header is set to Internal. Again the email won’t be blocked by the rule (because the rule is only for external email, internal mails are bypassed)

Did I miss the scenario? Could you please explain the exact problem scenario so that I can do more testing in my lab?

Not applicable
Yes this is a pretty botched up scenario and organizations have started taking notice of this design flow and microsofts response of getting this fixed using transport rules has been pretty flawed. They have the source and destination code control and it would be good if they put some engineering on this.

This fix does not work when:

1. Senders with calendar delegation forward meetings.

2. Senders that are on O365 hybrid but are striping their headers for security concerns.

Not applicable
Hi Arindam,

Some info on our environment and then I will confirm the scenario:

-Exchange 2016 Hybrid mode. All user mailboxes in cloud.

-We have "Centralized Mailflow" enabled. My understanding now of what this really does, is a process in the tenant look at a message during transport, and if it hasn't come from on prem, it's sent on prem (even user to user - cloud hosted mb to cloud hosted mb)

-Our MX records point to an on premise SMTP relay.

-These relays pass email to our on premise Exchange servers, which then transfer it to the tenant.

Scenario:

-All users are in the same cloud tenant. Boss1 had delegate User1. Boss1 has set up his delegation such that notices are forwarded/copied to the Delegate (user1).

-Boss1 gets a meeting invitation from user2 (a tenant mailbox user) and delegation forwards on to user1. User1 receives it.

-Boss1 gets a meeting invitation from an external sender, and his delegation configuration forwards it to user1. User1 does not receive the message.

-For User1 to get these messages, we had to add an exception to the transport rule of "Is message type 'Calendaring'"

Not applicable
Hi Arindam,

Great Article. I am little stuck though.

We are using Symantec Message Labs as the email filtering service.

Emails route from on-prem to Office 365 (For now)

I am not able to figure out what mailflow rule to create on the On-Prem Server to Allow only emails from Symantec IP's https://support.symantec.com/en_US/article.INFO4532.html

I cannot just add the subnets I guess I will have to add each and every IP in the Rule example above?

Not applicable
HI Naveen, Adding each IP will work.....otherwise you can also look at some unique header which is added by Symantec (see email header which is routed to on-premises through Symantec) and created a transport rule based on that condition.