Export Office 365 Mail Traffic Report with PowerShell

As an admin, it is important to keep track of the users’ sent and received emails in the Office 365 environment. Using a mail traffic report, you can identify any email activity anomalies and take necessary action to overcome security and compliance challenges. Using mail traffic report, you can get a number of emails sent and received by a per-user in your Office 365 tenant.


How to get the Office 365 Mail Traffic Report?  

You can use any one of the below methods to get the Office 365 email statistics report based on your requirement.  

  • Email activity report – You can export email activity report available in the Microsoft 365 Admin Center. Using this report, you can view how many emails each user has sent and received over a given period. You can generate this report for the last 7, 30, 90, and 180 days, but it won’t work with a custom period.  
  • Message Trace – You can use Message Trace in the Security and Compliance Center to get email flow report. However, you can’t get individual users sent and received email count from this report.  
  • PowerShell – You can generate a email traffic report using PowerShell. You can use either Get-Messagetrace or Get-MailTrafficReportGet-MailTrafficTopReport cmdlets. With Get-MessageTrace, you can get email traffic data for the past 10 days. Whereas, Get-MailTrafficTopReport can generate mail traffic statistics report for the past 90 days.  

The first two methods are easy and UI based, whereas PowerShell helps in automation and quick filtering. So, in this blogwe are going to use Get-MailTrafficTopReport to generate an exchange mail traffic report. 


Export Office 365 Mail Traffic Statistics by User with PowerShell 

With Get-MailTrafficTopReport, you will get inbound and outbound email counts separately in different records or rows. You need to aggregate multiple entries to get the desired result. To ease your work, we have created a user-friendly PowerShell script.  

The script will help you to get a nicely formatted Office 365 email traffic statistics report. The report shows the users along with their incoming and outgoing email traffic count based on their daily email activity. By default, the script can get email traffic report for the past 90 days. You can change the time range using available filters. 


Download Script: MailTrafficreport.ps1


Script Highlights: 

  • The script uses modern authentication to connect to Exchange Online. 
  • The script can be executed with MFA enabled account too. 
  • Exports report results to CSV. 
  • Allows you to generate email statistics report for custom period. 
  • Automatically installs the EXO V2 module (if not installed already) upon your confirmation. 
  • Allows you to filter the mail traffic report for organization users alone. 
  • The script is scheduler friendly. I.e., Credential can be passed as a parameter instead of saving inside the script. 


Sample Output:

The exported report contains following attributes: Date, User Name, Number of sent mail and Number of received mail.

Mail traffic report Office 365


Exchange Email Traffic Report – Script Execution Steps: 

Step 1: Download the script.  

Step 2: Start Windows PowerShell as Administrator.  

Step 3: To run this script, you can choose any one of the below methods.   

 Method 1: Execute script with non-MFA account     

Method 2: Execute script using MFA account   

Method 3: Execute script by explicitly mentioning credential (Scheduler friendly). 


More Use-cases of ‘Office 365 Email Statistics Report’ 

Export Office 365 Email Traffic Statistics by User: 

If you wonder how to count the number of emails sent and received in outlook per day, you can run this script as follows. 

The output file contains detailed mail traffic info of each user with their inbound and outbound email flow count for past 90 days 


Export Office 365 Sent and Received Mail Report for a Custom Period: 

You can generate an email activity report for custom period by mentioning –StartDate and –EndDate params. 

Using these params, you can generate email traffic report for the last 7 days, 30 days, 90 days, or any other required period. 

The exported report contains users sent and received email count from July 24th to July 31st. 


Export Mail Statistics Info for Organization Users (Excludes External Users): 

To get email traffic report for the organization’s users, execute the script with –OnlyOrganizationUsers switch param. This will exclude external domain users. 

Note: If an external user added as a Guest user in your organization, then the user considered as an organization’s user. 


Get Monthly Mail Traffic Report: 

To get mail traffic report for past 30 days, you can execute the script as follows. 

The mail traffic report contains sent and received email count for past 30 days. You can change the period based on your need. 


Schedule Mail Traffic Report: 

Since this email traffic statistics PowerShell script can take sent and received email count for the last 90 days, you may require old traffic data for analysis. In that case, scheduling will help you to keep the audit log for more than 90 days. 

To run PowerShell script task from the scheduler, you can use below the format. 


Get more Detailed Mailbox Traffic Reports:

To get more detailed email activity reports on

    • Users’ email statistics
      • Daily mail sent and received count by users
      • Daily active users
      • Email statistics summary
    • Email activities
      • All mails
      • Emails sent using send-as
      • Emails sent using send-on-behalf
    • Email protection reports
      • Spam mails sent and received
      • Malware mails sent and received
    • Top email statistics
      • Top mail senders
      • Top mail receivers
      • Top spam senders and receivers
      • Top malware senders and receivers
      • Top malware sent and received

you can take a look at AdminDroid Microsoft 365 reporting and auditing tool.

Additionally, AdminDroid provides 950+ pre-built reports and 18 smart visually appealing dashboards to know about your Office 365 environment at a glance. This tool provides reports on Office 365 reporting, auditing, analytics, usage statistics, security & compliance, etc.

Office 365 email traffic reportExchange Mailbox usage reportusage_adoption_dashboardPowerShell free Office 365 Reporting Tool

Besides, AdminDroid provides over 100+ reports and a handful of dashboards completely for free. It includes reports on Users, Licenses, Groups, Group Members, Devices, Login Activities, Password Changes, License Changes, and more. The free edition doesn’t have any restrictions in reporting functionalities such as customization, scheduling, and exporting. For your Azure AD reporting and auditing needs, you can download Free Office 365 reporting tool by AdminDroid and see how it helps for you.


I hope this blog will help you to find the number of emails sent and received in outlook per day. You can also use this report for analyzing user activity. If you have any queries or requirements, share it with us through the comment section.