Extract an email attachment and save to a location

This knowledgebase article explains how to extract attachments from an inbound email and save them to disk.

This is achieved by mapping a variable to the email Attachment parameter field in the Email Trigger (SMTP) event tool. The variable data can then by saved to disk using the Save File tool.

For detailed instructions please see below.

Creating the Variable

A Datafile variable must first be created so that it will be available for selection when configuring the Email Trigger (SMTP) event tool. The datafile option allows files to be stored in the variable.

  1. Begin by creating a new variable and provide it with a relevant name, for example Attachments.
  2. Within the Details tab of the variable properties, expand the Type drop down list and select Datafile.
  3. Tick the boxes Parameter and Array.
    Note: When a Datafile variable is set up as an Array, it allows any number of file attachments to be stored from an inbound SMTP email.
  4. Parameter Attributes should be set to In,Out and Scope set to Task Instance.
    1Figure 1. Details tab of the variable properties showing options selected for a Datafile type variable.

Email Trigger (SMTP) Event Tool – Mapping the variable

Using the Mapping table of the Email Trigger (SMTP) event tool, the variable can now be mapped to the Attachment parameter field of an email. This field only becomes available for selection when this type of variable has been created for mapping.

  1. Open the Email Trigger (SMTP) Event tool.
  2. Within the Mapping table click on (unmapped)for the Attachments variable and select Attachment from the drop down list.
    2Figure 2. This example screenshot shows a task that will be triggered when an email is received with the subject being ‘Demo Email’. The Datafile type variable is used to store the email attachments.

Saving the Attachment

The variable that has stored the email attachments can now be utilised.

  1. Create a Save File step, this can be placed directly after the Email Trigger (SMTP) Event step. Provide an appropriate name then select the Main tab.
  2. Drag the Attachments variable from the task browser into the Value field.
    Capture 1(1)Figure 3. Utilising the ‘Attachment’ variable.
  3. Specify a save location by using the Browse button at the end of the Path field. Each attachment stored by the variable will be saved using the original file name of the attachment.5Figure 4. Completed Main tab of the Save File tool.

This completes the article on saving an email attachment.

Return to – Setting up an Email Trigger (SMTP) event trigger step