What I would like to do is retrieve the email for a specific user(generic account). I’m not sure if that’s possible. Currently, I’m able to get and read email from my own inbox and parse out the information that I want but I want to be able to impersonate another user. I plan on running this as a task. Below is what I currently have.
`
Add-Type -AssemblyName “Microsoft.Office.Interop.Outlook” | Out-Null
$olFolder = “Microsoft.Office.Interop.Outlook.olDefaultFolders” -as [type]
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNameSpace(“MAPI”)
$folder = $namespace.getDefaultFolder($olFolder::olFolderInBox)
$folder = $namespace
$items = $folder.Items | Where-Object {$_.UnRead -eq $true}
foreach($f in $items)
{ $reader = $null
$reader = New-Object System.IO.StringReader($f.Body)
while($true)
{
$line = $reader.ReadLine()
if($line -ne $null)
{
if($line.Contains(“User:”))
{
[int]$startingIndex = $line.IndexOf(‘:’) + 1
[int]$stringLength = $line.IndexOf(‘(’) - $startingIndex
$user = $line.Substring($startingIndex,$stringLength).Trim()
Write-Verbose -Message “User: $user”
#Send me an email on this user
Send-SpecialEmailAboutUser -$useract $user
#set the message to be marked as read.
$f.UnRead = $false
break
}
}
}
$reader.Close()
Write-Host “Done…”
`