WordPress.com



# Invkoing Outlook API and creating Objects[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Outlook")| Out-Null$outlook = new-object -ComObject 'Outlook.Application'# Getting available namesapces, to navigate to Inbox. $ns = $outlook.getnamespace("MAPI")$inbox = $ns.GetDefaultFolder(6)$unreadcount =$inbox.unreaditemcount# This function Greets you Depending upon the Time of the dayfunction get-Greeting(){$Hour = (Get-Date).TimeOfDay.Hoursif($Hour -ge 0 -and $Hour -lt 12){ $greet = "Good Morning"}elseif($Hour -ge 12 -and $Hour -lt 16){ $greet = "Good After noon"}else{ $greet = "Good Evening"}return $greet}# This function removes and unwanted special character that make the Speech difficult to understandfunction Clean-String($Str){ $Ht = @{ '#' = ' ' '<' = ' ' '>' = ' ' '*' = ' '} $SpecialChar = "[$(-join $ht.Keys)]"$FinalStr = [regex]::Replace($Str,$SpecialChar,{$ht[$args[0].value]})Return $FinalStr}# Creating object of Speech Application Programming Interface$Siri = (New-Object -ComObject SAPI.SPVoice)$Siri.Rate = -2$Siri.Speak("$(get-greeting) `Prataeek you have $unreadcount unread emails in your Inbox" ) | Out-Null# Traversing each and every Sub-folder of your outlook and speaking you the unread email counts per folder$inbox.folders | ?{$_.unreaditemcount -ne 0}|foreach{ $Siri.Speak("$($_.name) Sub folder has $($_.unreaditemcount) unread emails") | Out-Null}# Targeting a special folder where you want SAPI to read each unread mail for you$TargetFolder = $inbox.folders| ?{$_.name -like '*Manager*'} # identify the folder with a specific name$Siri.Speak("Checking for email sent to you from Manager , This may take a while, please stay with me") | Out-Null# Within the target folder data mining unread emails sent to you$emails = $TargetFolder.items | select -Last 100 | ?{$_.unread -eq $true -and $_.to -like 'Prateek*'} | sort receivedtime -Descending if($emails.Count -eq 0){ $siri.Speak("No Unread Emails to you found, sent from Manager")}else{ $Siri.Speak("Total of $($emails.count) unread emails found, loading each email one by one") $i=1foreach($e in $emails){$subject = $e.subject$subject = Clean-String $subject # Removing special characters$body = $e.body$body = Clean-String $body # Removing special characters# Creating message format for SAPI$q = "Subject : " + $subject + "`n" + "Message : " + (($body) -split "From:")[0] # Splits the message and outputs only the top email not the trailing ones$q.tolower() #Convert the message format to lowercase as SAPI reads Capital Alphabets differently$siri.Speak("Message $i . $q") | Out-Null$i++}} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download