Archive email attachments and collect every 'From' email address

Question

"We would like to extract all email attachments from incoming emails and archive them to a local or network folder. Also for marketing purposes we would like to store the From email address, from the person who send the email to us."

Configuration

  1. Create a new channel with the name "Archive email attachments and save emails"
  2. Set the schedule to Periodic scheduling and set a time interval of 10 minutes.

Note: commercial email providers like Gmail, Hotmail, Outlook tend to use a restriction and only allow a polling interval of 10 minutes to prevent attacks!

  1. For Input use Email as input type.
  2. Configure the email connection. In our case we use Microsoft Exchange to connect and monitor our Office 365 mailbox. You can use a specific login with your username (e.g. my@company.com), password and domain (e.g. company.com). As Exchange Web Services (EWS) URL: you could most likely use https://outlook.office365.com/EWS/Exchange.asmx.
    (In case of doubt: ask your local IT administrator.)
  3. After you configured the connection settings, navigate to the Options-tab and and select the folder you want to monitor by clicking the Browse-button.
    In our case we monitor the INBOX.
  4. For the option Data to return: select Only the attachment(s).
  5. Optionally you can select an Attachment filter. This allows you to only process certain types of attachments.
    We only want to process emails that have PDF documents attached. By using a regular expression (regex) we filter out files with a pdf extension: (?i).*[.]pdf$
  6. Skip the Input Filter and also skip the Conversion tab.
  7. For the Output select Local/Network in case you want to archive the documents to a local or network folder.
  8. For Post-Action we will configure two actions on success.
  9. First, we will save the email addresses from the From-field by using a simple PowerShell script.
    Click the Add-button to create a Success-Post-Action.
  10. As Type select Dataprocessor and Output Type select Script.
  11. Create a Script parameter by clicking the Add-button in the Script parameters section.
  12. Click the Edit button next to the parameter, and turn on the Enable recognition for:, and select Property: From.
    Close the dialog by clicking OK.
  13. Click the Edit button next to the Script-label.
  14. For Script language: select PowerShell and fill in this PowerShell script below and close the script editor dialog. (Feel free to modify the Path-location.)
function ProcessData($lg, $data, $parameters) {
    # add PowerShell code here 
    
                if ($parameters) {
                   # We use index zero ($scriptParamsArray[0]) because we process only attachments.
                   # In case we process email+attachments, the index zero will the the email content.
                   [Winking.FileProcessor.Infrastructure.Logic.FilterResult[]]$scriptParamsArray = $parameters
                               $scriptParamsArray[0].AdjustedResultString | Add-Content -Path "E:\FileProcessor\Winking\Ricoh\scriptout\myemails.txt"
                }

    $boolResult = $true; # boolean with result to return
    return $boolResult;
}
  1. As second Post-Action we will mark the email as read. Therefor, click the Add-button to create a Success-Post-Action. Select Type: Process and select the Mark as read option.

It is a good practice to first mark the email as read and afterwards delete it. Some email servers do not delete emails when they are not first being marked as read.

Summary

You should have learned how to process email attachments and archive the attachments. By using the attachments filter from the email you can filter out attachments that end with a specific file extension, or that contain specific words or numbers. For example, this would allow you to only archive PDF attachments from emails.

The Input Filter works on the complete email, not on the attachments (as an attachment is contained inside an email). Therefor the Input Filter is very suited to filter out specific email accounts. With a regular expression it is easy to filter out only emails coming from specific accounts or domains.

This articles also demonstrated the used of a Script output in a Post-Action. PowerShell has been used as script language. The variables which are passed to the ProcessData function have a fixed type. This can be hard to understand, feel free to contact us for more information.

Video

File Processor: Archive email attachments and collect every 'From' email address