Scandinavian PowerShell User Group

PowerShell and Outlook

rated by 0 users
This post has 0 Replies | 1 Follower

Top 10 Contributor
Male
Posts 44
Points 1,455
Fredrik Wall Posted: 11-14-2008 11:37

If you have a list of person that you send mail to you will experiense soon or later that mail will bounce.
When people change their mail adresses, quit etc you need to check your adresses.

One way are to use PowerShell to look in an mailbox for Undeliverable mails and then make a list of them
without duplicates.

$olApp = New-Object -com Outlook.Application
$namespace = $olApp.GetNamespace("MAPI")
$myMailbox = $namespace.Folders.Item("Mailbox - My Mailbox")
$myInbox = $myMailbox.Folders.Item("Inbox")
$myFolder = $myInbox.Folders.Item("System med")

foreach ($myitems in $myFolder.items)
{
 if ($myitems.subject = "Undeliverable")
 {
 $mytest = $myitems.body | Out-File -FilePath "c:\mail.txt" -Append
 } 
}

$topers = Select-String -Path "c:\mail.txt" -Pattern "To: <"
$topers | foreach {$_ -replace ">", "" -replace "To: <", "" -replace "c:\\mail.txt:","" -replace "\d","" -replace ":",""} | Out-File -FilePath "c:\topers.txt" -Append

Get-Content c:\topers.txt | Select-Object -Unique | Out-File -FilePath "c:\bounce.txt" -Append

Page 1 of 1 (1 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems