Utilizing Sender Flags in EWS

Utilizing Sender Flags in EWS Sender Flags are an Outlook Function that let you set a comply with up flag on Message when your sending it in addition to having the ability to set a Recipient Followup flag if you wish to. (eg)

What occurs in Alternate once you set a Sender Flag on a Message is documented within the Informational Flagging Protocol doc http://msdn.microsoft.com/en-us/library/cc433487(v=exchg.80).aspx . If you wish to do the identical factor to a Message your sending in EWS there’s nothing within the strongly typed lessons to assist out so you could manually set two of the prolonged properties which might be documented in that protocol doc earlier than you ship the message and the Retailer will do the remaining on submit. (Extra particularly what occurs with the properties concerned is documented right here http://msdn.microsoft.com/en-us/library/ee217246(v=exchg.80).aspx )
The essential properties which might be concerned with sender flags are the PidTagSwappedToDoData which is used to Retailer the details about what sender flags your need (eg in Outlook configured through the above dialogue field).  This can be a binary property containing an variety of Flags, The textual content for the Message Flags and the DateTime values for the Begin and DueDate. The total construction of the property is documented in http://msdn.microsoft.com/en-us/library/ee201575(v=exchg.80).aspx
The DateTime values used on this Property are saved as a 4-byte integer which might be expressed because the variety of minutes since 00:00:00 on January 1, 1601, in UTC. To get this Integer the strategy I used is a TimeSpan between the Date you need and January 1, 1601, in UTC, you may then get the TotalMinutes for the timespan as an Integer.
 TimeSpan ts = new DateTime(2013,12,01,0,0,0,0,DateTimeKind.Utc) – new DateTime(1601, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
The opposite essential property is the PidTagSwappedToDoStore which is utilized by the Retailer after the Message is submitted. To make use of that is EWS you could assemble it primarily based on the format documented in http://msdn.microsoft.com/en-us/library/ee203516%28v=exchg.80%29.aspx . The data vital for this may be acquire by means of AutoDiscover. 
I’ve created a Powershell and EWS Pattern for setting a Sender Flag on a Message with a Begin and DueDate. I’ve put a download of this script right here the code itself appears like

  1. ## Get the Mailbox to Entry from the 1st commandline argument  
  2.   
  3. $MailboxName = $args[0]  
  4.   
  5. $SenderFlagText = “This is a Test Blah Blah”  
  6. $FlagStartDate = (Get-Date).AddDays(1)  
  7. $FlagDueDate = (Get-Date).AddDays(7)  
  8.  
  9.  
  10. ## Load Managed API dll    
  11. Add-Sort -Path “C:Program FilesMicrosoftExchangeWeb Services2.0Microsoft.Exchange.WebServices.dll”    
  12.    
  13. ## Set Alternate Model    
  14. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Alternate2010_SP2    
  15.    
  16. ## Create Alternate Service Object    
  17. $service = New-Object Microsoft.Alternate.WebServices.Knowledge.ExchangeService($ExchangeVersion)    
  18.    
  19. ## Set Credentials to use two choices are availible Option1 to use explict credentials or Possibility 2 use the Default (logged On) credentials    
  20.    
  21. #Credentials Possibility 1 utilizing UPN for the home windows Account    
  22. $psCred = Get-Credential    
  23. $creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  24. $service.Credentials = $creds        
  25.    
  26. #Credentials Possibility 2    
  27. #service.UseDefaultCredentials = $true    
  28.    
  29. ## Select to ignore any SSL Warning points precipitated by Self Signed Certificates    
  30.    
  31. ## Code From http://poshcode.org/624  
  32. ## Create a compilation setting  
  33. $Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider  
  34. $Compiler=$Supplier.CreateCompiler()  
  35. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  36. $Params.GenerateExecutable=$False  
  37. $Params.GenerateInMemory=$True  
  38. $Params.IncludeDebugInformation=$False  
  39. $Params.ReferencedAssemblies.Add(“System.DLL”) | Out-Null  
  40.   
  41. [email protected] 
  42.   namespace Native.ToolkitExtensions.Internet.CertificatePolicy{ 
  43.     public class TrustAll : System.Internet.ICertificatePolicy { 
  44.       public TrustAll() {  
  45.       } 
  46.       public bool CheckValidationResult(System.Internet.ServicePoint sp, 
  47.         System.Safety.Cryptography.X509Certificates.X509Certificates cert,  
  48.         System.Internet.WebRequest req, int drawback) { 
  49.         return true; 
  50.       } 
  51.     } 
  52.   } 
  53. @   
  54. $TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)  
  55. $TAAssembly=$TAResults.CompiledAssembly  
  56.  
  57. ## We now create an occasion of the TrustAll and connect it to the ServicePointManager  
  58. $TrustAll=$TAAssembly.CreateInstance(“Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll”)  
  59. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  60.  
  61. ## finish code from http://poshcode.org/624  
  62.    
  63. ## Set the URL of the CAS (Shopper Entry Server) to use two choices are availbe to use Autodiscover to discover the CAS URL or Hardcode the CAS to use    
  64.    
  65. #CAS URL Possibility 1 Autodiscover    
  66. $service.AutodiscoverUrl($MailboxName,{$true})    
  67. “Using CAS Server : “ + $Service.url     
  68.     
  69. #CAS URL Possibility 2 Hardcoded    
  70.    
  71. #$uri=[system.URI] “https://casservername/ews/exchange.asmx”    
  72. #$service.Url = $uri      
  73.    
  74. ## Elective part for Alternate Impersonation    
  75.   
  76. operate hex2binarray($hexString){  
  77.     $i = 0  
  78.     [byte[]]$binarray = @()  
  79.     whereas($i -le $hexString.size – 2){  
  80.         $strHexBit = ($hexString.substring($i,2))  
  81.         $binarray += [byte]([Convert]::ToInt32($strHexBit,16))  
  82.         $i = $i + 2  
  83.     }  
  84.     return ,$binarray  
  85. }  
  86.   
  87. operate GetAutoDiscoverSettings{  
  88.     param (  
  89.             $adEmailAddress = “$( throw ’emailaddress is a mandatory Parameter’ )”,  
  90.             $Credentials = “$( throw ‘Credentials is a mandatory Parameter’ )”  
  91.           )  
  92.     course of{  
  93.         $adService = New-Object Microsoft.Alternate.WebServices.AutoDiscover.AutodiscoverService($ExchangeVersion);  
  94.         $adService.Credentials = $Credentials  
  95.         $adService.EnableScpLookup = $false;  
  96.         $adService.RedirectionUrlValidationCallback = {$true}  
  97.         $UserSettings = new-object Microsoft.Alternate.WebServices.Autodiscover.UserSettingName[] 3  
  98.         $UserSettings[0] = [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::UserDN  
  99.         $UserSettings[1] = [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::InternalRpcClientServer  
  100.         $UserSettings[2] = [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::UserDisplayName  
  101.         $adResponse = $adService.GetUserSettings($adEmailAddress , $UserSettings);  
  102.         return $adResponse  
  103.     }  
  104. }  
  105. operate GetAddressBookId{  
  106.     param (  
  107.             $AutoDiscoverSettings = “$( throw ‘AutoDiscoverSettings is a mandatory Parameter’ )”  
  108.           )  
  109.     course of{  
  110.         $userdnString = $AutoDiscoverSettings.Settings[[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::UserDN]  
  111.         $userdnHexChar = $userdnString.ToCharArray();  
  112.         foreach ($factor in $userdnHexChar) {$userdnStringHex = $userdnStringHex + [System.String]::Format(“{0:X}”, [System.Convert]::ToUInt32($factor))}  
  113.         $Supplier = “00000000DCA740C8C042101AB4B908002B2FE1820100000000000000”  
  114.         $userdnStringHex = $Supplier + $userdnStringHex + “00”  
  115.         return $userdnStringHex  
  116.     }  
  117. }  
  118. operate GetStoreId{  
  119.     param (  
  120.             $AutoDiscoverSettings = “$( throw ‘AutoDiscoverSettings is a mandatory Parameter’ )”  
  121.           )  
  122.     course of{  
  123.         $userdnString = $AutoDiscoverSettings.Settings[[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::UserDN]  
  124.         $userdnHexChar = $userdnString.ToCharArray();  
  125.         foreach ($factor in $userdnHexChar) {$userdnStringHex = $userdnStringHex + [System.String]::Format(“{0:X}”, [System.Convert]::ToUInt32($factor))}   
  126.         $serverNameString = $AutoDiscoverSettings.Settings[[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::InternalRpcClientServer]  
  127.         $serverNameHexChar = $serverNameString.ToCharArray();  
  128.         foreach ($factor in $serverNameHexChar) {$serverNameStringHex = $serverNameStringHex + [System.String]::Format(“{0:X}”, [System.Convert]::ToUInt32($factor))}  
  129.         $flags = “00000000”  
  130.         $ProviderUID = “38A1BB1005E5101AA1BB08002B2A56C2”  
  131.         $versionFlag = “0000”  
  132.         $DLLFileName = “454D534D44422E444C4C00000000”  
  133.         $WrappedFlags = “00000000”  
  134.         $WrappedProviderUID = “1B55FA20AA6611CD9BC800AA002FC45A”  
  135.         $WrappedType = “0C000000”  
  136.         $StoredIdStringHex = $flags + $ProviderUID + $versionFlag + $DLLFileName + $WrappedFlags + $WrappedProviderUID + $WrappedType + $serverNameStringHex + “00” + $userdnStringHex + “00”  
  137.         return $StoredIdStringHex  
  138.     }  
  139. }  
  140.   
  141.   
  142. operate GetPidTagSwappedToDoData {  
  143.     param (  
  144.         $FlagText = “$( throw ‘FlagText is a mandatory Parameter’ )”,  
  145.         $StartTime = “$( throw ‘StartTime is a mandatory Parameter’ )”,  
  146.         $DueTime = “$( throw ‘DueTime is a mandatory Parameter’ )”  
  147.     )  
  148.     course of{  
  149.         $todoTimeFlagged  = “01000000”;  
  150.         $PidLidFlagRequest = “”  
  151.         $PidLidFlagRequestHexChar = $FlagText.ToCharArray();  
  152.         $PidLidFlagRequest = [System.BitConverter]::ToString([System.Text.UnicodeEncoding]::Unicode.GetBytes($FlagText)).Substitute(“-“,“”)  
  153.         #Pad Flag to 512 Bytes  
  154.         for ($padCnt = $PidLidFlagRequest.Size / 2; $padCnt -lt 512; $padCnt++) {  
  155.                 $PidLidFlagRequest = $PidLidFlagRequest + “00”;  
  156.         }  
  157.         $stime = New-Object System.DateTime $StartTime.12 months,$StartTime.Month,$StartTime.Day,0,0,0,0,Utc  
  158.         $dtime =  New-Object System.DateTime $DueTime.12 months,$DueTime.Month,$DueTime.Day,0,0,0,0,Utc  
  159.         $etime = New-Object System.DateTime 1601, 1, 1, 0, 0, 0, 0,Utc  
  160.         [System.TimeSpan]$StartDateTimets = $stime – $etime  
  161.         [System.TimeSpan]$DateDueTimets = $dtime – $etime  
  162.         $HexDateStartTime = [System.Convert]::ToInt64($StartDateTimets.TotalMinutes).ToString(“X8”);  
  163.         $HexDateStartTime = $HexDateStartTime.Substring(6, 2) + $HexDateStartTime.Substring(4, 2) + $HexDateStartTime.Substring(2, 2) + $HexDateStartTime.Substring(0, 2);  
  164.         $HexDateDueTime = [System.Convert]::ToInt64($DateDueTimets.TotalMinutes).ToString(“X8”);  
  165.         $HexDateDueTime = $HexDateDueTime.Substring(6, 2) + $HexDateDueTime.Substring(4, 2) + $HexDateDueTime.Substring(2, 2) + $HexDateDueTime.Substring(0, 2);  
  166.         $ulVersion = “01000000”;  
  167.         $dwFlags = “79000000”; #dwToDoItem,rtmStartDate,rtmDueDate ,wszFlagTo ,fReminderSet   
  168.         $dwToDoItem = $todoTimeFlagged;  
  169.         $wszFlagTo = $PidLidFlagRequest;  
  170.         $rtmStartDate = $HexDateStartTime;  
  171.         $rtmDueDate = $HexDateDueTime;  
  172.         $rtmReminder = “00000000”;  
  173.         $fReminderSet = “00000000”;  
  174.         return ($ulVersion + $dwFlags + $dwToDoItem + $wszFlagTo + $rtmStartDate + $rtmDueDate + $rtmReminder + $fReminderSet);  
  175.     }  
  176. }  
  177.  
  178. #$service.ImpersonatedUserId = new-object Microsoft.Alternate.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  179. $SenderFlagEmail = New-Object Microsoft.Alternate.WebServices.Knowledge.EmailMessage -ArgumentList $service    
  180. $SenderFlagEmail.ToRecipients.Add([email protected]);  
  181. $SenderFlagEmail.Topic = “test”;  
  182. $SenderFlagEmail.Physique =  New-Object  Microsoft.Alternate.WebServices.Knowledge.MessageBody([Microsoft.Exchange.WebServices.Data.BodyType]::HTML,“test”);  
  183. $PR_SWAPPED_TODO_DATA = new-object Microsoft.Alternate.WebServices.Knowledge.ExtendedPropertyDefinition(0x0E2D,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);  
  184. $PR_SWAPPED_TODO_STORE = new-object Microsoft.Alternate.WebServices.Knowledge.ExtendedPropertyDefinition(0x0E2C,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);  
  185.   
  186. $adset = GetAutoDiscoverSettings -adEmailAddress $MailboxName -Credentials $creds  
  187. $storeID = “”  
  188. if($adset -is [Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverResponse]){  
  189.     Write-Host (“Get StoreId”)  
  190.     $storeID = GetStoreId -AutoDiscoverSettings $adset  
  191. }  
  192.   
  193. $senderFlagHex = GetPidTagSwappedToDoData -FlagText $SenderFlagText -StartTime $FlagStartDate  -DueTime $FlagDueDate  
  194.   
  195. $SenderFlagEmail.SetExtendedProperty($PR_SWAPPED_TODO_DATA,(hex2binarray $senderFlagHex));  
  196. $SenderFlagEmail.SetExtendedProperty($PR_SWAPPED_TODO_STORE,(hex2binarray $storeID));  
  197. $SenderFlagEmail.SendAndSaveCopy();  
  198. Write-Host (“Message Sent”)  

Tags:

Rate this article!

Related Posts

Leave a Reply