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.
- Begin by creating a new variable and provide it with a relevant name, for example Attachments.
- Within the Details tab of the variable properties, expand the Type drop down list and select Datafile.
- 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.
- Parameter Attributes should be set to In,Out and Scope set to Task Instance.
Figure 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.
- Open the Email Trigger (SMTP) Event tool.
- Within the Mapping table click on (unmapped)for the Attachments variable and select Attachment from the drop down list.
Figure 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.
- 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.
- Drag the Attachments variable from the task browser into the Value field.
Figure 3. Utilising the ‘Attachment’ variable. - 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.Figure 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