Skip to main content

Posts

Showing posts from July, 2013

Forwarding a Message as an Attachment using the EWS Managed API and Powershell

While you can easily create an Inbox rule to forward a Message as an Attachment, doing this programmatically in EWS isn't that straight forward. As there is no direct method in EWS to attach an existing Store item a work around is needed. With this workaround we use the MimeContent of an existing email message which will allow you to create an ItemAttachment of this existing message (using the method from this post) in the Inbox and maintain all the Mime Properties and attachments on the message your forwarding. Note this method doesn't maintain full fidelity of a Message as it won't include any MAPI properties or Exchange rich datatypes which may or may not be important. The following sample demonstrates how to forward the more recently received email in the Inbox as an Item Attachment using the MimeContent (and also setting the MessageFlags property to make sure the message appears sent).  $folderid=  new -object Microsoft.Exchange.WebServices.Data.FolderId([Micro

Creating Item Attachments with the EWS Managed API with Powershell

Item Attachments in EWS allow you to create an Attachment that is of a Rich Exchange type such as an EmailMessage, Task, Post, Contact etc or even your own custom form if your using these. Although one thing you can't do with an Item attachment is attach an existing Exchange Item. To use ItemAttachments in Powershell you need to use reflection in .NET as it involves invoking a Generic Method which is not that straight forward in Powershell. The following is an example of creating a Task as an Item Attachment in Powershell using reflection $mail  =  New-Object  Microsoft.Exchange.WebServices.Data.EmailMessage( $service );   $AtColtype  = ( "Microsoft.Exchange.WebServices.Data.AttachmentCollection" ) -as  "Type"    $Tasktype  = ( "Microsoft.Exchange.WebServices.Data.Task" ) -as  "Type"    $methodInf  =  $AtColtype .GetMethod( "AddItemAttachment" );   $AddItmAttachMethod  =  $methodInf .MakeGenericMethod( $Tasktype );
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.