Home Download Order Modules Articles Support
Saving Attachments Automatically with Outlook Print E-mail
User Rating: / 24
PoorBest 
Written by Positic   

So, automatic saving of attachments - what is it for? Here is a simple example. Let's assume you work in the office and have to process reports from your subdivisions on a daily basis. This requires you to import the attached files, for example, in your favorite bookkeeping program. Thus, every day you have to perform a great number of routine actions to save the attachments.

Use the "Save Attachments" module, built in the Potolook plug-in, to make your daily routine easier.

In order to complete this task, you will have to create a new sorting rule. The sorting criterions can be whichever you like; however, for the action you will need to set "Perform user-defined action", as shown on the figure below:

Rule for saving of attachments in Microsoft Outlook

Next, you should configure this action using the "Edit" button. Create a new rule and then select "Save attached files" as the name, and then set the required options. In the settings dialog that appears, you can select the folder where the files will be saved and select a program that will run automatically once the file has been created. Confirm all changes and close all the dialogs. Now, when this rule triggers, attachments will be saved to the folder you have specified. You can create any number of such rules if needed.

Let's now take a look at a more complex situation. We will need to save attachments to diverse folders depending on, for instance, date shown in the message subject or the date when the message was received. We will need to write a tiny JScript code for that; this code will process our incoming messages.

For performing an action over messages when they are being sorted, the program uses the script "Action to perform when this rule triggers". It can be edited through the menu "?-Service" / "Settings" / "Events" / "Actions". You can edit the script in any external text editor. By default, the file is located here: "My Documents\My Templates and Scripts for EMail\Scripts\rule.js". The location can be altered as well.

The script looks as follows:


if(command=='SaveAttachments'){
  var Directory = "c:\\Attachments\\"

  var RegExpData = /\d{1,2}[\.\-\/\\]\d{1,2}[\.\-\/\\]\d{2,4}/gi;
  var DateMail;
  var Match = RegExpData.exec(item.Subject+"");
  if(Match!=null){
    DateMail = Match[0]
  }else{
    // If no date found in Subject, use the creation date
    DateMail = FormatDate(new Date(item.CreationTime), 'dd.mm.yyyy');
  }

  if(DateMail){
    // Convert date to the format: dd.mm.yyyy
    DateMail = DateMail.replace(/[\.\-\/\\]/gi, '.');
    DateMail = DateMail.replace(/^(\d){1}\./gi, '0$1.');
    DateMail = DateMail.replace(/\.(\d){1}\./gi, '.0$1.')
    var MyDir = DateMail.replace(/\.(\d{2})$/gi, '.20$1');
    var fso = func.CreateObject("Scripting.FileSystemObject");
    // Loop for all attachments in the message
    for(var i=1;i<=item.Attachments.Count;i++){
      var DirForAttach = Directory+MyDir;
      if(!fso.FolderExists(DirForAttach)){ fso.CreateFolder(DirForAttach); }
      item.Attachments(i).SaveAsFile(DirForAttach+'\\'+item.Attachments(i).FileName);
    }
    fso = null
  }
}

The script can be added to the tail of the "rule.js" file. Please note that path where attachments are to be stored is assigned by the "Directory" variable in the line 2, and each backslash must be doubled. The folder you have specified in the variable must exist. To create folders automatically, the script will search message subject for a date value in the format dd.mm.yyyy (dd/mm/yyyy or dd-mm-yyyy). If none of such values has been found, it will use the message creation date. If you are familiar with JScript, you can customize the folder name generation process for any other terms.

We now need to create a rule in order to run our script. To do that, create a rule with the required criterions (as described above) and select "Perform user-defined action" for action. For the action name, enter "Run configurable parser". In the parameters, enter "SaveAttachments". Save this rule. Attachments will now be saved in the diverse folders depending on the date in the message subject (or the message creation date).

 

 

Last Version


Last Version Potolook
Potolook plugin for Microsoft Outlook
© 2004-2011 Positic Software. All rights reserved.
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.