- The threat: Direct Send lets anything on the internet connect to your MX endpoint (
contoso-com.mail.protection.outlook.com) on port 25 and submit unauthenticated mail from your own accepted domain. Attackers abuse it to deliver internal-looking phishing (fake HR, payroll, voicemail notices) that never touches a compromised account. - The control:
Set-OrganizationConfig -RejectDirectSend $truerejects anonymous messages that use your accepted domains unless they arrive over a matching partner inbound connector. It is opt-in for existing tenants and takes up to ~30 minutes to apply. - Do this first: Inventory multifunction printers, scanners and line-of-business apps that use Direct Send, move them to authenticated SMTP, High Volume Email, or a certificate/IP-based connector, then enable the setting. The year-end SMTP AUTH Basic Auth disablement makes this a good time to fix both together.
Microsoft introduced Reject Direct Send to close one of the oldest gaps in Exchange Online mail flow. By default, Exchange Online accepts anonymous SMTP sessions on its MX endpoint, and if the sender address uses one of your accepted domains the message is treated as coming from your organisation. That's convenient for an office printer sending "Scan to Email"βand equally convenient for a phishing kit.
This runbook walks through how to find legitimate Direct Send senders, migrate them, and enable the control safely. The audit commands were run against the LAB 365 dev tenant (where RejectDirectSend was False and no partner connectors existed).
Architecture: Direct Send Before and After Hardening
1. Check Your Current Configuration
Connect-ExchangeOnline -UserPrincipalName [email protected]
# Is Reject Direct Send already on?
Get-OrganizationConfig | Format-List RejectDirectSend
# Which domains are "yours" (Direct Send spoofs these)
Get-AcceptedDomain | Format-Table DomainName, DomainType, Default -AutoSize
# Existing partner / on-premises inbound connectors (these remain allowed)
Get-InboundConnector | Format-Table Name, ConnectorType, Enabled, SenderIPAddresses, TlsSenderCertificateName -AutoSize
2. Find Candidate Direct Send Senders with Get-MessageTraceV2
Message trace doesn't expose an "authenticated" flag directly, so this script builds a candidate list: messages whose sender uses one of your accepted domains and that arrived from a source IP. Mail that users send from Outlook normally has no external FromIP, while printers, scanners and apps sending anonymously over port 25 show the device's public egress IP. Validate each candidate before acting.
#Requires -Modules ExchangeOnlineManagement
param(
[ValidateRange(1, 90)]
[int]$DaysBack = 10,
[string]$OutputCsv = ".\DirectSend-Candidates-$(Get-Date -Format 'yyyyMMdd').csv"
)
$Accepted = (Get-AcceptedDomain).DomainName
$KnownConnectorIPs = (Get-InboundConnector | Where-Object Enabled).SenderIPAddresses
$End = (Get-Date).ToUniversalTime()
$Floor = $End.AddDays(-$DaysBack)
$Rows = [System.Collections.Generic.List[object]]::new()
# Walk back in <=10-day windows (Get-MessageTraceV2 limit), following cursor pagination
while ($End -gt $Floor) {
$Start = if ($End.AddDays(-10) -lt $Floor) { $Floor } else { $End.AddDays(-10) }
$CursorEnd = $End; $CursorRcpt = $null
do {
$p = @{ StartDate = $Start; EndDate = $CursorEnd; ResultSize = 5000 }
if ($CursorRcpt) { $p.StartingRecipientAddress = $CursorRcpt }
$Batch = @(Get-MessageTraceV2 @p -WarningAction SilentlyContinue)
$Batch | ForEach-Object { $Rows.Add($_) }
if ($Batch.Count -eq 5000) {
$CursorEnd = $Batch[-1].Received.ToUniversalTime(); $CursorRcpt = $Batch[-1].RecipientAddress
} else { break }
} while ($true)
$End = $Start
}
$Candidates = $Rows | Where-Object {
$domain = ($_.SenderAddress -split '@')[-1]
($Accepted -contains $domain) -and $_.FromIP -and ($KnownConnectorIPs -notcontains $_.FromIP)
}
$Summary = $Candidates | Group-Object FromIP, SenderAddress | ForEach-Object {
[PSCustomObject]@{
FromIP = $_.Group[0].FromIP
SenderAddress = $_.Group[0].SenderAddress
Messages = $_.Count
FirstSeenUTC = ($_.Group.Received | Measure-Object -Minimum).Minimum
LastSeenUTC = ($_.Group.Received | Measure-Object -Maximum).Maximum
SampleSubject = $_.Group[0].Subject
}
} | Sort-Object Messages -Descending
$Summary | Export-Csv $OutputCsv -NoTypeInformation -Encoding UTF8
Write-Host "Trace rows: $($Rows.Count) | Direct Send candidates: $($Candidates.Count) | Unique IP/sender pairs: $(@($Summary).Count)" -ForegroundColor Cyan
$Summary | Select-Object -First 20 | Format-Table -AutoSize
How to validate a candidate: open the message in Message Trace (or ask the recipient for full headers) and check for X-MS-Exchange-Organization-AuthAs: Anonymous. Your own office egress IPs sending as [email protected] are legitimate devices to migrate. Unknown IPs sending as executives or HR are spoofing attempts, which is the evidence your CAB will want.
Option B: Find Direct Send Devices via Microsoft Defender XDR Advanced Hunting (KQL)
If your tenant has Microsoft Defender for Office 365, querying EmailEvents in Microsoft Defender portal → Hunting → Advanced hunting is even faster than PowerShell message trace loops because you can filter directly on isempty(Connectors) and AuthenticationDetails:
// 1. Inventory candidate Direct Send devices & IPs (last 30 days)
EmailEvents
| where Timestamp >= ago(30d)
| where EmailDirection in ("Inbound", "Intra-org")
| where SenderFromDomain in ("contoso.com", "subsidiary.com") // Replace with your accepted domains
| where isempty(Connectors)
| where isnotempty(SenderIPv4)
| summarize
MessageCount = count(),
FirstSeen = min(Timestamp),
LastSeen = max(Timestamp),
SampleRecipients = make_set(RecipientEmailAddress, 5),
SampleSubjects = make_set(Subject, 3)
by SenderIPv4, SenderFromAddress, EmailDirection, AuthenticationDetails
| order by MessageCount desc
To unpack the JSON verdicts inside AuthenticationDetails (SPF, DKIM, DMARC, CompAuth) and separate unauthenticated printers/scanners or spoofing attempts from normal mail:
// 2. Unpack AuthenticationDetails for per-message inspection
EmailEvents
| where Timestamp >= ago(14d)
| where EmailDirection in ("Inbound", "Intra-org")
| where SenderFromDomain in ("contoso.com")
| where isempty(Connectors)
| where isnotempty(SenderIPv4)
| extend AuthDetails = parse_json(AuthenticationDetails)
| evaluate bag_unpack(AuthDetails)
| project
Timestamp,
EmailDirection,
SenderIPv4,
SenderFromAddress,
RecipientEmailAddress,
Subject,
SPF,
DKIM,
DMARC,
CompAuth,
NetworkMessageId
| order by Timestamp desc
3. Migrate Legitimate Senders (Pick One Per Device)
| Option | Best for | Notes |
|---|---|---|
| Partner inbound connector (certificate or static IP) | Office MFPs and scanners behind a fixed public IP; on-prem relay servers | Remains allowed after RejectDirectSend. Prefer certificate-based connectors where possible. |
| SMTP client submission (port 587) with OAuth | Modern apps and devices that support OAuth 2.0 | Basic Auth SMTP AUTH is being disabled by default. Don't migrate devices onto Basic Auth. |
| High Volume Email (HVE) / Azure Communication Services | Bulk internal notifications, LOB apps without OAuth support | Avoids per-mailbox sending limits. |
| On-prem SMTP relay (Exchange SE / IIS) | Many legacy devices that can only speak anonymous SMTP | Devices relay locally; the relay authenticates to EXO through a connector. |
New-InboundConnector -Name "Partner - Onprem Relay (cert)" `
-ConnectorType Partner `
-SenderDomains "*" `
-RequireTls $true `
-RestrictDomainsToCertificate $true `
-TlsSenderCertificateName "relay.contoso.com"
4. Enable Reject Direct Send and Monitor
# Enable (opt-in; propagation can take ~30 minutes)
Set-OrganizationConfig -RejectDirectSend $true
# Verify
Get-OrganizationConfig | Format-List RejectDirectSend
# Roll back immediately if a business-critical device was missed
# Set-OrganizationConfig -RejectDirectSend $false
After enabling, re-run the candidate script daily for a week, and review the Direct Send reporting in the Exchange admin center if it's available in your tenant. Rejected senders get an NDR saying Direct Send isn't allowed for the organisation, so record the exact status code you see in your CAB notes. Any internal device that starts failing is one you missed in step 2.
Third-party forwarding: Services that relay mail back into your tenant without Sender Rewriting Scheme (SRS) may be blocked. Give them a partner inbound connector before you enable the setting.
Related LAB 365 Guides
- SMTP AUTH Basic Auth December 2026 Disablement: Audit & Migration
- Exchange Online Custom Message Trace Retention & Get-MessageTraceV2 Archiving
- Audit SPF, DKIM & DMARC for All M365 Tenant Domains
- Setting up Anonymous Relay on Exchange Server
References & Official Microsoft Documentation
- Introducing more control over Direct Send in Exchange Online, Exchange Team Blog on Microsoft Tech Community. Search the blog for the original preview and GA announcements.
- How to set up a multifunction device or application to send email using Microsoft 365
- Set-OrganizationConfig (ExchangePowerShell)
- New-InboundConnector (ExchangePowerShell)
- Get-MessageTraceV2 (ExchangePowerShell)
π¬ Reader Comments & Feedback
Did this runbook help, or did Microsoft change a cmdlet or UI menu? Share your feedback below.
Leave a Comment or Report an Update