Automating Outlook Tasks
JAMS has the ability to automate Outlook tasks such as saving attachments or exporting email information.
While Outlook profile settings and Exchange security settings can complicate these tasks, Outlook provides COM objects for automation within Powershell.
The following examples parse the Test folder within the Outlook Inbox.
Example #1. Exporting the Sender email addresses from an Outlook folder:
$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$mapi = $ol.getnamespace("mapi")
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
$msgs = $inbox.Folders.Item("Test")
$msgs.items | Select-Object SenderName, SenderEmailAddress -unique | export-Csv c:\emails.csv -noTypeInformation
Example #2. Saving the email attachments from an Outlook folder:
$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$mapi = $ol.getnamespace("mapi")
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
$msgs = $inbox.Folders.Item("Test")
foreach ($group in $msgs.items |% {$_.attachments} | group filename)
{
trap {
Write-Host There was a problem saving $fName
continue
}
$fName = "C:\TEMP\$($group.Name)"
$group.Group[0].saveasfile($fName)
if ($?) {Write-Host $fName was saved succesfuly.}
}
Posted Tuesday, March 09, 2010
by
TonyC
http://www.jamssupport.com/KnowledgebaseArticle50099.aspx