Hi @Daisyahoy
Please kindly note that our forum doesn't support scripting.
If you need suggestions on your script, please consider posing in Windows Server Powershell forum or Exchange Development forum.
(You can add the corresponding tags windows-server-powershell and office-exchange-server-dev to your question to post in these forums)
Are you using Exchange On-premises or Exchange Online (Office 365)?
For Exchange On-premises, here is a script which may be helpful.
You can download it via this link: https://web.archive.org/web/20200324061458/https://gallery.technet.microsoft.com/scriptcenter/Count-sent-and-recceived-f9c66cf7
To use the script to generate a report and send to a specific mailbox, you may need to modify the following fields (modify to to be your mailbox and SmtpServer to be your Exchange server name) and run the script via Exchange Management Shell:
############ Send emails with results
send-mailmessage -to "******@domain.com" -from "StatMails@exchange" -subject "Stats mails From $StartDate To $EndDate" -body ($body | out-string) -BodyAsHTML -SmtpServer "xxx.xxx.xxx.xxx:YY"
For Exchange Online, you can use the built-in Email activity report feature in Microsoft 365 admin center.
Direct link: https://admin.microsoft.com/Adminportal/Home?#/reportsUsage/EmailActivity
It would generate a detailed report of the email activity in your tenant.
Example:
If you would like to display the user names instead of showing anonymous user names, please follow the steps in this link:
Microsoft 365 reports show anonymous user names instead of actual user names
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.