August 12, 2020

Export Office 365 Mail Traffic Report with PowerShell

by Kathy Cooper

6 min read

No Comments

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 reports, you can also get the number of emails sent and received by each user in your Office 365 tenant.

How to get the Office 365 Mail Traffic Report?

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

  • Email activity report – You can export the email activity report available in the Microsoft 365 Admin Center. Using this report, you can see 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 Exchange Admin center to get an email flow report. However, you can’t get individual users sent and received email count from this report.
  • PowerShell – You can generate an email traffic report using PowerShell. You can use the Get-MessageTrace, Get-MailTrafficReport, Get-MailTrafficTopReport, and Get-MailTrafficATPReport cmdlets. With Get-MessageTrace, you can get email traffic data for the past 10 days. Whereas, Get-MailTrafficTopReport and Get-MailTrafficReport cmdlets are under deprecation. Get-MailTrafficATPReport will not provide a user-based mail count.

The first two methods are easy and UI-based, whereas PowerShell helps in automation and quick filtering. So, in this blog, we use the PowerShell cmdlet Get-MailTrafficSummaryReport to generate an exchange mail traffic report.

Apr’22 Update: Since Get-MailTrafficReport and Get-MailTrafficTopReport cmdlets are deprecated, we have updated our script with the alternative cmdlet Get-MailTrafficSummaryReport.

Export Office 365 Mail Traffic Statistics by User with PowerShell

With Get-MailTrafficSummaryReport, you will get aggregated inbound and outbound email counts for a given period. To track the daily email count, you need to run the cmdlet for each day. To ease your work, we have created a user-friendly PowerShell script.

The script will help you get a 5+ nicely formatted Office 365 email traffic statistics report. By default, the script will generate an email received report. The report shows the users, along with their incoming email traffic count based on their daily email activity. You can also generate sent mail, spam, and malware reports using the built-in parameters.

Download Script: MailTrafficReport.ps1

Script Highlights:

  • The script can generate 5+ email statistics reports like emails sent, emails received, spam received, and malware received count.
  • 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 reports for a 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., Credentials can be passed as a parameter.

Microsoft 365 Email Statistics Report – Sample Output:

The exported report contains the following attributes: Date, User Name, Number of mails sent/Number of mails received /Number of spam received/Number of malwares received.

Office 365 mail traffic report by user statistics

Exchange Email Traffic Report – Script Execution Steps:

To run this script, you can choose any of the methods below.

Method 1: Execute script with MFA account

Method 2: Execute script using non-MFA account

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

If the admin account has MFA, you need to disable MFA using the Conditional Access policy to make this method work.

More Use-cases of ‘Office 365 Sent and Received Email Report’

Our script supports built-in parameters and switches to generate Office 365 sent and received email by user report. We have listed a few use cases below.

Export Office 365 Received Email 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.

By default, the script will generate Microsoft 365 received email report for the given period. You can retrieve max of the past 90 days’ data.

The output file contains detailed mail traffic info of each user with their inbound and outbound email flow count for the given period.

Get Office 365 Sent Mail Report:

You can track sent email activity using the sent email report. To view the number of emails sent in outlook per day, you can run this script with –MailsSent param.

The exported report contains users’ sent email count for the given period.

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

You can generate an email activity report for a custom period by mentioning –StartDate and –EndDate params while running the script.

Using these parameters, you can generate email traffic reports for the last 7 days, 30 days, 90 days, or any custom period.

To get sent email statistics, run the script as follows.

The exported report contains users’ sent email count from Mar 21st to Mar 27th.

You can also use the above format to generate received mails, spam recipients, and malware recipient reports.

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. It will exclude external domain users.

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

Office 365 Spam Recipient Report:

To identify top spam recipients and monitor how much spam is being detected, you can run the script with the –SpamsReceived parameter.

For example,

This report will help you improve email security, such as anti-spam and spam-filtering mechanisms.

Exchange Malware Recipient Report:

To identify incoming malware emails and top malware recipients in your organization, execute the script with –MalwaresReceived switch param.

This report will help identify how much malware is being detected by Exchange Online Protection.

Get Monthly Mail Traffic Report:

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

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

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 keep the audit log for more than 90 days.

To automate PowerShell script from Windows Task Scheduler, you can use the below format.

If the admin account has MFA, you need to disable MFA using the Conditional Access policy to make this method work.

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.

AdminDroid provides 250+ pre-built email reports and smart dashboards to know more about your organization’s email activities at a glance. By using the ‘Views’ and ‘Advanced Filter’ options, you can create custom reports based on your requirement.

Each report provides AI-powered graphical analysis to gain insights and better understand the data in a visually appealing manner.

AdminDroid Office 365 mail traffic statistics report

Office 365 Email Dashboards:

Exchange Online Email traffic dashboard

Email activity report

Additionally, AdminDroid provides 1500+ pre-built reports and 20 smart visually appealing dashboards to know about your Office 365 environment in detail. This tool provides reports on Office 365 reporting, auditing, analytics, usage statistics, security & compliance, etc.

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.

Share article