Needs to get all external mail

Rita Rita 60 Reputation points
2025-08-04T13:38:18.2933333+00:00

Hello

Please i need your help on this issue.

Needs to get all external mail send count for certain groups.

EX- If group named "IT" I need to know how much mail they have send to extremal parties.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jack-Bu 2,610 Reputation points Microsoft External Staff Moderator
    2025-08-04T14:43:20.28+00:00

    Hello Rita Rita,

    Welcome to Microsoft Q&A forum.

    Regarding your inquiry, to get the external mail send count for the "IT" group in Microsoft 365, use Exchange Online PowerShell to query message trace data, as there’s no direct report in the Admin Center for group-level external emails. Below is the PowerShell script for the solution:

    # Connect to Exchange Online PowerShell
    
    Install-Module -Name ExchangeOnlineManagement
    Connect-ExchangeOnline -UserPrincipalName <******@yourdomain.com>
    
    # Get "IT" Group Members and Count External Emails: Run this script to count emails sent by "IT" group members to external recipients (outside your domain) in the last 30 days:
    
    $GroupName = "IT"
    $Domain = "yourdomain.com"
    $StartDate = (Get-Date).AddDays(-30)
    $EndDate = Get-Date
    $GroupMembers = Get-DistributionGroupMember -Identity $GroupName | Select-Object -ExpandProperty PrimarySmtpAddress
    $ExternalMailCount = 0
    foreach ($Member in $GroupMembers) {
        $ExternalMails = Get-MessageTrace -SenderAddress $Member -StartDate $StartDate -EndDate $EndDate | Where-Object { $_.RecipientAddress -notlike "*@$Domain" }
        $ExternalMailCount += $ExternalMails.Count
    }
    # Replace yourdomain.com with your organization’s domain. Adjust $StartDate if needed.
    
    # Export to CSV (Optional):
    
    $Results = @()
    foreach ($Member in $GroupMembers) {
        $ExternalMails = Get-MessageTrace -SenderAddress $Member -StartDate $StartDate -EndDate $EndDate | Where-Object { $_.RecipientAddress -notlike "*@$Domain" }
        $Results += [PSCustomObject]@{
            Sender = $Member
            ExternalMailCount = $ExternalMails.Count
        }
    }
    $Results | Export-Csv -Path "C:\Your own csv path" -NoTypeInformation
    

    Notes:

    • Requires Global Admin or Exchange Admin permissions.
    • Message trace data is limited to 30 days.
    • For large groups, the script may take time to run.

    In case you run into any Error or require further assistance, please feel free to comment below. I here to help!


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.