by

Sending a No Reply, No ReplyAll, No Ahead E-mail utilizing EWS and Powershell

Sending a No Reply, No ReplyAll, No Ahead E-mail utilizing EWS and Powershell I’ve you have not seen this earlier than Gavin Smyth from Microsoft Analysis put collectively this cool VSTO plugin to permit you to ship an E-mail from Outlook that can disable the Reply, ReplyAll and Ahead Buttons on the Outlook ribbon http://analysis.microsoft.com/en-us/initiatives/researchdesktop/noreplyall.aspx and the the best way to posts concerning the VSTO http://blogs.msdn.com/b/gsmyth/archive/2011/09/18/noreply-vsto-add-in-wrap-up.aspx .

Be aware this solely works in Outlook (not OWA or ActiveSync and so forth) however principally what a customers would see after they obtain a message is

How this works is it units the PidLidVerbStream Property on a message which is usually documented within the http://msdn.microsoft.com/en-us/library/ee218541(v=exchg.80).aspx protocol doc. I say principally as a result of the format you get when utilizing the strategies from the NoReply Addin is slightly completely different from the format documented which is for Voting buttons however its ok to work with. The Verbs that this property refers to are the usual Verbs that MAPI implements that are documented in http://msdn.microsoft.com/en-us/library/workplace/cc815879(v=workplace.15).aspx .

So to make use of this similar property in an EWS script you’ll be able to simply set it utilizing the Prolonged Properties, the worth you utilize is slightly difficult as solely the voteoption format is totally documented. However as a result of that is fairly customary you’ll be able to reduce a previous the Hex Values which comprises the 2 streams from this property out of an current message after which simply change the bits that both permits or disable the Verbs for what you need to allow or disable on the Message your sending.

So that is what the next script does is means that you can ship a message utilizing EWS and set the choices to allow and disable every of those verbs.

Within the script I’ve bought the next customized object the place you’ll be able to set the verbs on or off

  1. $VerbSetting = “” | Choose DisableReplyAll,DisableReply,DisableForward,DisableReplyToFolder  
  2. $VerbSetting.DisableReplyAll = $true  
  3. $VerbSetting.DisableReply = $true  
  4. $VerbSetting.DisableForward = $true  
  5. $VerbSetting.DisableReplyToFolder = $true  

The remainder of the script builds the VerbStream worth property based mostly on the setting within the customized object and the remainder of the script is an ordinary EWS script to ship a message.

I’ve put a download of this script right here the script itself seems to be like

  1. $MailboxName = $args[0]  
  2. $SentTo = $args[1]  
  3.   
  4. $VerbSetting = “” | Choose DisableReplyAll,DisableReply,DisableForward,DisableReplyToFolder  
  5. $VerbSetting.DisableReplyAll = $true  
  6. $VerbSetting.DisableReply = $true  
  7. $VerbSetting.DisableForward = $true  
  8. $VerbSetting.DisableReplyToFolder = $true  
  9.   
  10. ## Load Managed API dll    
  11.   
  12. ###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT  
  13. $EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path ‘Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Companies’|Kind-Object Identify -Descending| Choose-Object -First 1 -ExpandProperty Identify)).‘Set up Listing’) + “Microsoft.Exchange.WebServices.dll”)  
  14. if (Take a look at-Path $EWSDLL)  
  15.     {  
  16.     Import-Module $EWSDLL  
  17.     }  
  18. else  
  19.     {  
  20.     “$(get-date -format yyyyMMddHHmmss):”  
  21.     “This script requires the EWS Managed API 1.2 or later.”  
  22.     “Please download and install the current version of the EWS Managed API from”  
  23.     “http://go.microsoft.com/fwlink/?LinkId=255472”  
  24.     “”  
  25.     “Exiting Script.”  
  26.     exit  
  27.     }  
  28.     
  29. ## Set Change Model    
  30. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Change2010_SP2    
  31.     
  32. ## Create Change Service Object    
  33. $service = New-Object Microsoft.Change.WebServices.Information.ExchangeService($ExchangeVersion)    
  34.     
  35. ## Set Credentials to use two choices are availible Option1 to use explict credentials or Possibility 2 use the Default (logged On) credentials    
  36.     
  37. #Credentials Possibility 1 utilizing UPN for the home windows Account    
  38. $psCred = Get-Credential    
  39. $creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  40. $service.Credentials = $creds        
  41.     
  42. #Credentials Possibility 2    
  43. #service.UseDefaultCredentials = $true    
  44.     
  45. ## Select to ignore any SSL Warning points prompted by Self Signed Certificates    
  46.     
  47. ## Code From http://poshcode.org/624  
  48. ## Create a compilation atmosphere  
  49. $Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider  
  50. $Compiler=$Supplier.CreateCompiler()  
  51. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  52. $Params.GenerateExecutable=$False  
  53. $Params.GenerateInMemory=$True  
  54. $Params.IncludeDebugInformation=$False  
  55. $Params.ReferencedAssemblies.Add(“System.DLL”) | Out-Null  
  56.   
  57. $TASource=@ 
  58.   namespace Native.ToolkitExtensions.Internet.CertificatePolicy{ 
  59.     public class TrustAll : System.Internet.ICertificatePolicy { 
  60.       public TrustAll() {  
  61.       } 
  62.       public bool CheckValidationResult(System.Internet.ServicePoint sp, 
  63.         System.Safety.Cryptography.X509Certificates.X509Certificates cert,  
  64.         System.Internet.WebRequest req, int downside) { 
  65.         return true; 
  66.       } 
  67.     } 
  68.   } 
  69. @   
  70. $TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)  
  71. $TAAssembly=$TAResults.CompiledAssembly  
  72.   
  73. ## We now create an occasion of the TrustAll and connect it to the ServicePointManager  
  74. $TrustAll=$TAAssembly.CreateInstance(“Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll”)  
  75. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  76.   
  77. ## finish code from http://poshcode.org/624  
  78.     
  79. ## Set the URL of the CAS (Consumer Entry Server) to use two choices are availbe to use Autodiscover to discover the CAS URL or Hardcode the CAS to use    
  80.     
  81. #CAS URL Possibility 1 Autodiscover    
  82. $service.AutodiscoverUrl($MailboxName,{$true})    
  83. “Using CAS Server : “ + $Service.url     
  84.      
  85. #CAS URL Possibility 2 Hardcoded    
  86.     
  87. #$uri=[system.URI] “https://casservername/ews/exchange.asmx”    
  88. #$service.Url = $uri      
  89.     
  90. ## Optionally available part for Change Impersonation    
  91.     
  92. #$service.ImpersonatedUserId = new-object Microsoft.Change.WebServices.Information.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  93.   
  94.   
  95. operate Get-VerbStream{    
  96.     param (    
  97.             $VerbSettings = “$( throw ‘VerbSettings is a mandatory Parameter’ )”    
  98.           )    
  99.     course of{    
  100.       
  101.     $Header = “02010400000000000000”  
  102.     $ReplyToAllHeader = “055265706C790849504D2E4E6F7465074D657373616765025245050000000000000000”  
  103.     $ReplyToAllFooter = “0000000000000002000000660000000200000001000000”  
  104.     $ReplyToHeader = “0C5265706C7920746F20416C6C0849504D2E4E6F7465074D657373616765025245050000000000000000”  
  105.     $ReplyToFooter = “0000000000000002000000670000000300000002000000”  
  106.     $ForwardHeader = “07466F72776172640849504D2E4E6F7465074D657373616765024657050000000000000000”  
  107.     $ForwardFooter = “0000000000000002000000680000000400000003000000”  
  108.     $ReplyToFolderHeader = “0F5265706C7920746F20466F6C6465720849504D2E506F737404506F737400050000000000000000”  
  109.     $ReplyToFolderFooter = “00000000000000020000006C00000008000000”  
  110.     $VoteOptionExtras = “0401055200650070006C00790002520045000C5200650070006C007900200074006F00200041006C006C0002520045000746006F007200770061007200640002460057000F5200650070006C007900200074006F00200046006F006C0064006500720000”  
  111.     if($VerbSetting.DisableReplyAll){  
  112.         $DisableReplyAllVal = “00”  
  113.     }  
  114.     else{  
  115.         $DisableReplyAllVal = “01”  
  116.     }  
  117.     if($VerbSetting.DisableReply){  
  118.         $DisableReplyVal = “00”  
  119.     }  
  120.     else{  
  121.         $DisableReplyVal = “01”  
  122.     }  
  123.     if($VerbSetting.DisableForward){  
  124.         $DisableForwardVal = “00”  
  125.     }  
  126.     else{  
  127.         $DisableForwardVal = “01”  
  128.     }  
  129.     if($VerbSetting.DisableReplyToFolder){  
  130.         $DisableReplyToFolderVal = “00”  
  131.     }  
  132.     else{  
  133.         $DisableReplyToFolderVal = “01”  
  134.     }  
  135.     $VerbValue = $Header +  $ReplyToAllHeader + $DisableReplyAllVal + $ReplyToAllFooter + $ReplyToHeader + $DisableReplyVal +$ReplyToFooter + $ForwardHeader + $DisableForwardVal + $ForwardFooter + $ReplyToFolderHeader + $DisableReplyToFolderVal + $ReplyToFolderFooter + $VoteOptionExtras  
  136.     return $VerbValue  
  137.     }  
  138. }  
  139.   
  140. operate hex2binarray($hexString){  
  141.     $i = 0  
  142.     [byte[]]$binarray = @()  
  143.     whereas($i -le $hexString.size – 2){  
  144.         $strHexBit = ($hexString.substring($i,2))  
  145.         $binarray += [byte]([Convert]::ToInt32($strHexBit,16))  
  146.         $i = $i + 2  
  147.     }  
  148.     return ,$binarray  
  149. }  
  150.   
  151.   
  152.   
  153. $VerbStreamProp = new-object Microsoft.Change.WebServices.Information.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Frequent,0x8520, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)  
  154.   
  155. $VerbSettingValue = get-VerbStream $VerbSetting  
  156.   
  157. $EmailMessage = New-Object Microsoft.Change.WebServices.Information.EmailMessage -ArgumentList $service    
  158. $EmailMessage.Topic = “Message Subject”    
  159. #Add Recipients      
  160. $EmailMessage.ToRecipients.Add($SentTo)    
  161. $EmailMessage.Physique = New-Object Microsoft.Change.WebServices.Information.MessageBody    
  162. $EmailMessage.Physique.BodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::HTML    
  163. $EmailMessage.Physique.Textual content = “Body”   
  164. $EmailMessage.SetExtendedProperty($VerbStreamProp,(hex2binarray $VerbSettingValue))  
  165. $EmailMessage.SendAndSaveCopy()