Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Daily report of quarantined e-mails in Exchange 2007

Posted on 2010-09-22
Last Modified: 2012-05-10
Hi, in our office we have a quarantine mailbox where all of our non-rejected spam goes.  Naturally, once in awhile it picks up message that are not spam.

Rather than having everyone check this spam inbox, I was thinking it would be really cool to automate this so that everyone would get a report each day of the messages that were sent to them and quarantined on the previous day.

So basically I'm guessing it would be a powershell script that queries the spam inbox, by date and To: field, and then sends an email to that person, listing the From: field and message subject.

What is the best way to do this?
Question by:jamorlando
  • 7
  • 3

Expert Comment

ID: 33735391
dont think its possible to use powershell to get the list of emails in a mailbox. but saying that i found the following to get the list of flagged emails


Author Comment

ID: 33735759
I tested this script on my computer and it worked.

So basically, I would need to set up a new machine with Outlook installed and have the default inbox be our spam inbox.  Then I would schedule a nightly powershell script to run.

Before I go further, is this the best way to do this?  Is there free software out there that already handles this?

Expert Comment

ID: 33735784
Not that i know of. but can always suggest the best teacher. www.google.com.. :)
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why


Author Comment

ID: 33735802
Never heard of it.  I use askjeeves.com (kidding)

Expert Comment

ID: 33735829
never heard of that as well.. ;). heard something about someone having a some sort of a search engine called 'ding'.. ;)
LVL 12

Expert Comment

ID: 33743490
I did something similar years ago, with the help of Sue Mosher, using a server side VB script that hit a Public Folder to generate a daily email containing all new messages of the day. I will see if I can find it and convert it to work with a mailbox. No promises, this is from the Exchange 2000 days and much has changed, but it stands to reason that it should still be possible.

Author Comment

ID: 33876280
Gus, were you ever able to find that script?

Author Comment

ID: 33884236
I set up a PC with Outlook installed with the Spam inbox.  Opened up a new thread in the Outlook forum.

Author Comment

ID: 33908165
First step ... I am able to export email folders from a date range to a PST file.

Export-Mailbox -Identity SPAM -IncludeFolders '\Inbox\Joe' -StartDate "10/13/2010" -EndDate "10/13/2010" -PSTFolderPath 'C:\Joe Yesterday Spam.pst'

Anyone know how to convert this to a .csv or .txt file so that I can parse it with a script?

Accepted Solution

jamorlando earned 0 total points
ID: 33948252

Author Comment

ID: 33983802
Actually ... I adandoned PSTViewerPro, because it's buggy.
I buckled down and forced myself to write some powershell.
Here's my script.  (To have this work you need to have message rules set up that puts people's quarantined spam into a subfolder with the inbox)

#Script by Jamie Orlando
#Last updated: 10/25/2010
#Recurses through subfolders in Inbox and e-mails each user the headers from their spam messages on the previous day
#***   Make sure the following command is entered into PowerShell before proceeding:
#***   Set-ExecutionPolicy RemoteSigned

$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$mapi = $ol.getnamespace("mapi")
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
$inboxFolders = $inbox.Folders | Select Name
$yesterdayDate = (Get-Date).AddDays(-1).toShortDateString()

foreach ($CurrentFolder in $inboxFolders)
   $CurrentRecipient = $CurrentFolder.Name  

   $msgs = $inbox.Folders.Item("$CurrentRecipient")
   $countSpam = 0
   foreach ($CurrentMsg in ($msgs.items | Sort-Object CreationTime))
      $CurrentMessageDate = $CurrentMsg.CreationTime.toShortDateString()

      if($CurrentMessageDate -eq $yesterdayDate)
         $CurrentMsg.Body | Out-File -Filepath C:\spambody.txt
         "Time: " + $CurrentMsg.CreationTime.toShortTimeString() | Out-File "C:\spamreport.txt" -Append
         $EmailFrom = select-string -pattern "From: " C:\spambody.txt | Select-Object Line | Select -First 1
         $EmailFrom.Line | Out-File "C:\spamreport.txt" -Append
         $EmailSubject = select-string -pattern "Subject: " C:\spambody.txt | Select-Object Line | Select -First 1
         $EmailSubject.Line | Out-File "C:\spamreport.txt" -Append
         "" | Out-File "C:\spamreport.txt" -Append
         remove-item "c:\spambody.txt"

   if($countSpam -ge 1)
      $SendingServer = "EXCHANGE01.ourcompany.com"
      $FromAddress = "SPAM@ourcompany.com"
      $ToAddress = $CurrentRecipient + "@ourcompany.com"
      $MessageSubject = $countSpam + " message(s) were quarantined on: " + $yesterdayDate
      $SpamOutput = Get-Content "c:\spamreport.txt" | Out-String

      $MessageBody = @"
On $yesterdayDate, $countSpam spam messages were quarantined for $CurrentRecipient.
If any of these messages are not spam, please e-mail IT_NOTIFY@ourcompany.com to retrieve the message.
Thank you,
IT Staff

      $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
      $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer

      remove-item "c:\spamreport.txt"

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
In-place Upgrading Dirsync to Azure AD Connect
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question