by

EWS Fundamentals: Message Flagging and Marking Messages Learn/Unread

EWS Fundamentals: Message Flagging and Marking Messages Learn/Unread Messages which are saved in Trade might be flagged in a lot of methods to point completely different states to the person or as an efficient methodology to immediate the person to motion (or make them keep in mind to do one thing).

Unread/Learn Flags

 Essentially the most generally used Flag in Trade is the Unread/Learn Message flag which is used so when a message arrives in Mailbox a person can observe which messages they’ve learn. In EWS this flag is surfaced within the API within the kind of a Strongly kind property isRead  https://msdn.microsoft.com/en-us/library/workplace/bb408987(v=exchg.150).aspx . (The underlying Retailer property that again that is PidTagMessageFlags property https://msdn.microsoft.com/en-us/library/ee160304(v=exchg.80).aspx  which is a bitwise flag representing many states of a message).

The opposite place the Unread Message flag is surfaced is on the Folder object within the guise of the Unread Merchandise depend. So within the under instance we Bind to Inbox folder and we will take a look at the Whole Variety of Objects in a Folder and the Whole variety of these which are unread

$folderid= new-object Microsoft.Trade.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)     
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
Write-Host ("Total Message Count : " + $Inbox.TotalCount)
Write-Host ("Total Unread Message Count : " +$Inbox.UnreadCount)

Marking all Messages in a Folder Learn

One of many new options added to EWS in 2013 was an operation that permits you to mark all messages as learn in a folder. Additionally with the opposite necessary function of having the ability to suppress Learn Receipts once you achieve this. Eg the next is a operate that can Mark all of the Messages in a Folder as Learn and Suppress Learn Recipients.

$folderId = FolderIdFromPath -FolderPath $FolderPath -SmtpAddress $MailboxName
if($folderId -ne $null){
$Folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)
Write-Host ("Total Message Count : " + $Folder.TotalCount)
Write-Host ("Total Unread Message Count : " +$Folder.UnreadCount)
Write-Host ("Marking all messags a unread in folder")
$Folder.MarkAllItemsAsRead($true)
}

Marking only one message as Learn

To mark simply the present message your enumerating in a operate as Learn as it’s essential do is use the isRead Strongly typed property eg the mark the final message acquired in a Mailbox learn

$folderid= new-object Microsoft.Trade.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)     
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$ivItemView = New-Object Microsoft.Trade.WebServices.Information.ItemView(1)
$fiItems = $service.FindItems($Inbox.Id,$ivItemView)
if($fiItems.Objects.Rely -eq 1)
{
$fiItems.Objects[0].isRead = $true
$fiItems.Objects[0].Replace([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AutoResolve);
}

All these instance are within the following GitHub Script https://github.com/gscales/Powershell-Scripts/blob/grasp/unReadModule.ps1

Flagging a Message for Comply with-up

Flagging a Message for follow-up is a typical process you would possibly do it to remind you {that a} message wants another actions on it after you’ve got learn it (eg it’s essential telephone the sender and so forth). In 2013 some strongly kind properties the place added to assist learn and set the follow-up flags. Nonetheless these do not cowl all of the attainable flag properties (listed right here) you would possibly wish to set when setting a followup specifically the followup Textual content (eg the customized choice in Outlook). To cater for this you should utilize a mix of Prolonged property’s and the strongly typed properties. Eg To flag the final message with a follow-up to name the sender in 1 hour you should utilize the next

$FlagRequest = New-Object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Widespread, 0x8530,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);  
$PR_FLAG_ICON = New-Object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition(0x1095,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);
$folderid= new-object Microsoft.Trade.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$ivItemView = New-Object Microsoft.Trade.WebServices.Information.ItemView(1)
$fiItems = $service.FindItems($Inbox.Id,$ivItemView)
if($fiItems.Objects.Rely -eq 1)
{
$fiItems.Objects[0].Flag.FlagStatus = [Microsoft.Exchange.WebServices.Data.ItemFlagStatus]::Flagged;
$fiItems.Objects[0].Flag.DueDate = $DueDate
$fiItems.Objects[0].Flag.StartDate = (Get-Date)

$fiItems.Objects[0].SetExtendedProperty($FlagRequest,$FollowupText)
$fiItems.Objects[0].SetExtendedProperty($PR_FLAG_ICON,$Shade)
$fiItems.Objects[0].Replace([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AutoResolve);
}

This instance is roofed within the following GitHub Script https://github.com/gscales/Powershell-Scripts/blob/grasp/flaggfollowup.ps1

Sender Flags are a extra superior Outlook function that permits you to transmit a particular flag to a recipient with the message. There is no such thing as a assist in EWS for setting any such flag however I’ve one other workaround resolution I’ve revealed earlier than for this http://gsexdev.blogspot.com.au/2013/12/using-sender-flags-in-ews.html