EWS Email Attachment Saver
This script looks for specific emails in an exchange users mailbox, downloads the attachments, then marks those emails as read and moves the messages to a processed folder for archiving.
- Determines the Folder ID of the processed folder
- Finds the correct email messages based on defined search filters (e.g. unread, subject, has attachments)
- Copy's the attachments to the appropriate download location(s)
- Mark emails as read and move to the processed folder
Check out my Blog Post: Using Powershell and Microsoft EWS Managed API to download attachments in Exchange 2016
- Exchange 2007 or newer
- Exchange Web Services (EWS) Managed API 2.2
The processed folder is a subfolder of the root of the users mailbox (e.g.
\\firstname.lastname@example.org\ProcessedFolder). The root of a users mailbox is called the Top Information Store. If your processed folder is a subfolder under any other folder you must change
To quickly view the outlook folder location, right click on a folder in outlook, then click properties.
Example: processed folder is a subfolder of the root mailbox:
$processedfolderpath = "/ProcessedFolder" $tftargetidroot = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$mailbox)
Example, processed folder is a subfolder of Inbox:
$processedfolderpath = "/Inbox/ProcessedFolder" $tftargetidroot = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$processedfolderpath)
- Create a Windows Service that will run the EWS Attachment Saver on an interval to check for applicable emails