Hi, I currently have the below setup but whenever I run it I get the email to my inbox but does not give me the numbers for the total amount of emails sent/received. Can anyone help?
$mailbox=""
$startDate=Get-Date
$endDate=Get-Date
$startDateFormatted=$startDate.AddDays(-7).ToShortDateString()
$endDateFormatted=$endDate.AddDays(-1).ToShortDateString()
$emailFrom = "no-reply@domain.com"
$emailTo = ""
$subject = "Weekly e-mail report"
$smtpServer = ""
$sendCount = Get-TransportServer | Get-MessageTrackingLog -Start "$startDateFormatted 00:00:00" -End "$endDateFormatted 23:59:59" - Sender $mailbox -resultsize unlimited | select-object -unique MessageId
$receiveCount = Get-TransportServer | Get-MessageTrackingLog -Start "$startDateFormatted 00:00:00" -End "$endDateFormatted 23:59:59" -Recipients $mailbox -resultsize unlimited | select-object -unique MessageId
$sendCountString = $sendCount.count
$receiveCountString = $receiveCount.count
$body = "Mailbox stats for: $mailbox $nl
Report date range: $startDateFormatted 00:00:00 - $endDateFormatted 23:59:59 $nl
Total e-mails sent: $sendCountString $nl
Total e-mails received: $receiveCountString"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
PS, we have Office365 also but I do not see the option to schedule report that way.
Thanks