I am trying to reply to emails using PowerShell, and the code below works successfully, but it doesn't show the original message I'm responding to:
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
Add-type -assembly "System.Runtime.Interopservices"
try {
$outlook = [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application')
$outlookWasAlreadyRunning = $true
}
catch {
try {
$Outlook = New-Object -comobject Outlook.Application
$outlookWasAlreadyRunning = $false
}
catch {
write-host "You must exit Outlook first."
exit
}
}
$namespace = $Outlook.GetNameSpace("MAPI")
$inbox = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$Folder = $inbox.Folders | where-object { $_.name -eq "Folder name" }
$mails = $Folder.Items | Where-Object {$_.Subject -like "This is the subject"}
foreach($mail in $mails) {
$reply = $mail.ReplyAll()
$reply.body = "TEST BODY"
$reply.save()
$inspector = $reply.GetInspector
$inspector.display()
}