Skip to main content

Save Attachments

Saves email attachments from a specified Microsoft Outlook email to a local directory. This node is essential for extracting documents, images, and files from emails for further processing in your automation workflows.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is set to true, no error will be caught and the automation will continue running. If a Catch node is used, it will have no effect.

Inputs

  • Mail Entry ID - The Entry ID of the email containing attachments. This ID is obtained from the entryId property of emails returned by Get Mail or Search Mail nodes.
  • Mail Store ID - The Store ID of the email account. This ID is obtained from the storeId property of emails returned by Get Mail or Search Mail nodes.
  • Directory Path - The local directory path where attachments will be saved. The directory must exist before running this node. Use full absolute paths (e.g., C:\\Downloads\\Attachments).

Outputs

This node produces no output values.

Options

This node has no additional options.

Example Usage

Save Attachments from Single Email

// First, get an email using Get Mail
const emails = $.GetMailResult;
const emailWithAttachment = emails[0]; // First email

// Configure Save Attachments node:
// Mail Entry ID: emailWithAttachment.entryId
// Mail Store ID: emailWithAttachment.storeId
// Directory Path: C:\Downloads\EmailAttachments

// All attachments from this email will be saved to the directory

Save Attachments from Multiple Emails

// Get emails with attachments
const emails = $.SearchMailResult; // Using Search Mail with [HasAttachments] = true filter

console.log(`Processing ${emails.length} emails with attachments`);

// For each email, use Save Attachments node
for (const email of emails) {
console.log(`Saving attachments from: ${email.subject}`);

// Use Save Attachments node with:
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: C:\Downloads\Attachments
}

Save Attachments to Organized Folders

// Get invoice emails
const invoiceEmails = $.SearchMailResult;

// Process each invoice
for (const email of invoiceEmails) {
// Extract invoice number from subject (e.g., "Invoice #12345")
const match = email.subject.match(/#(\d+)/);
const invoiceNumber = match ? match[1] : 'Unknown';

// Create folder name based on invoice number
const folderPath = `C:\\Invoices\\Invoice_${invoiceNumber}`;

// Create directory first (use File System node or ensure it exists)
// Then save attachments to this specific folder

// Configure Save Attachments node:
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: folderPath (computed above)

console.log(`Saved attachments for Invoice ${invoiceNumber}`);
}

Save Attachments by Date

// Get today's emails with attachments
const todayEmails = $.GetMailResult;

// Create date-based folder name
const today = new Date();
const dateFolder = today.toISOString().split('T')[0]; // YYYY-MM-DD format
const savePath = `C:\\EmailAttachments\\${dateFolder}`;

// For each email with attachments
for (const email of todayEmails) {
// Use Save Attachments node with:
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: savePath

console.log(`Saved attachments from ${email.from} to ${dateFolder} folder`);
}

Save Attachments and Track Saved Files

// Get email
const email = $.GetMailResult[0];

// Define save path
const savePath = 'C:\\Documents\\EmailAttachments';

// Use Save Attachments node to save files
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: savePath

// After saving, you can list the directory to see what was saved
// (Use File System List Directory node)

console.log(`Attachments saved from email: ${email.subject}`);
console.log(`Saved to: ${savePath}`);

Process Attachments After Saving

// Get report emails
const reportEmails = $.SearchMailResult;

for (const email of reportEmails) {
const savePath = 'C:\\Reports\\Temp';

// Save attachments using Save Attachments node
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: savePath

// After saving, process the files
// For example, if attachments are Excel files:
// 1. Use File System to list files in savePath
// 2. Use Excel package to read each file
// 3. Extract data
// 4. Store in database
// 5. Move or delete the files

console.log(`Processed attachments from: ${email.subject}`);
}

Save Attachments from Emails with Specific Keywords

// Search for emails with specific subject and attachments
// Filter: [Subject] LIKE '%Contract%' AND [HasAttachments] = true
const contractEmails = $.SearchMailResult;

console.log(`Found ${contractEmails.length} contract emails with attachments`);

// Create dedicated folder for contracts
const contractsPath = 'C:\\Legal\\Contracts\\Received';

for (const email of contractEmails) {
// Extract sender domain for subfolder organization
const senderDomain = email.from.split('@')[1];
const subfolder = `${contractsPath}\\${senderDomain}`;

// Use Save Attachments node:
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: subfolder

console.log(`Saved contract from ${email.from} to ${subfolder}`);
}

Conditional Attachment Saving

// Get emails
const emails = $.GetMailResult;

for (const email of emails) {
// Check if email has attachments by searching body or checking in Get Mail results
// In this example, we'll save attachments only from trusted senders

const trustedDomains = ['partner.com', 'vendor.com', 'client.com'];
const senderDomain = email.from.split('@')[1];

if (trustedDomains.includes(senderDomain)) {
const savePath = `C:\\TrustedAttachments\\${senderDomain}`;

// Use Save Attachments node:
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: savePath

console.log(`Saved attachments from trusted sender: ${email.from}`);
} else {
console.log(`Skipped attachments from: ${email.from} (untrusted domain)`);
}
}

Save Attachments and Move Email

// Get unprocessed emails with attachments
const emails = $.GetMailResult;

for (const email of emails) {
try {
const savePath = 'C:\\Attachments\\Processed';

// Step 1: Save attachments
// Use Save Attachments node:
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: savePath

console.log(`✓ Attachments saved from: ${email.subject}`);

// Step 2: Move email to Processed folder
// Use Move Mail node:
// EntryID: email.entryId
// Source Folder: INBOX
// Destination Folder: Processed

console.log(`✓ Email moved to Processed folder`);

} catch (error) {
console.error(`Failed to process email: ${email.subject}`, error);
}
}

Save Attachments with Logging

// Get email
const email = $.GetMailResult[0];

const savePath = 'C:\\EmailAttachments';
const logData = {
timestamp: new Date().toISOString(),
subject: email.subject,
from: email.from,
receivedDate: email.datetime,
savePath: savePath,
entryId: email.entryId
};

// Save attachments using Save Attachments node
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: savePath

// Log the operation
console.log('Attachment save operation:', JSON.stringify(logData, null, 2));

// Optionally save log to file or database
return logData;

Bulk Attachment Extraction

// Search for all emails with attachments in a date range
// Filter: [HasAttachments] = true AND [ReceivedTime] > '2024-11-01'
const attachmentEmails = $.SearchMailResult;

console.log(`Found ${attachmentEmails.length} emails with attachments`);

// Define base path
const basePath = 'C:\\BulkAttachmentExtraction';

// Create summary
const summary = {
totalEmails: attachmentEmails.length,
processed: 0,
failed: 0,
savedTo: basePath
};

for (const email of attachmentEmails) {
try {
// Use Save Attachments node for each email
// Mail Entry ID: email.entryId
// Mail Store ID: email.storeId
// Directory Path: basePath

summary.processed++;
} catch (error) {
summary.failed++;
console.error(`Failed to save attachments from: ${email.subject}`);
}
}

console.log('Bulk extraction summary:', summary);
return summary;

Tips for Effective Use

  1. Directory Must Exist: The directory specified in Directory Path must already exist. The node will not create directories. Use File System package to create directories if needed.

  2. Use Absolute Paths: Always use full absolute paths (e.g., C:\\Downloads\\Attachments), not relative paths like ./attachments.

  3. Windows Path Separators: In Windows, use double backslashes (\\) or forward slashes (/) in paths. Examples:

    • C:\\Documents\\Attachments
    • C:/Documents/Attachments
    • C:\Documents\Attachments ✗ (single backslash may cause issues in strings)
  4. Get Entry ID and Store ID: Always obtain Entry ID and Store ID from Get Mail or Search Mail nodes. Don't try to construct these manually.

  5. Check for Attachments: Before using Save Attachments, verify the email has attachments. You can search with [HasAttachments] = true filter or handle the error if no attachments exist.

  6. File Name Conflicts: If multiple emails have attachments with the same filename, they will overwrite each other if saved to the same directory. Consider organizing into subfolders.

  7. Large Attachments: Be mindful of disk space when saving many or large attachments. Consider adding cleanup routines.

  8. Organize by Metadata: Create folder structures based on email metadata (date, sender, subject) for better organization.

Common Errors and Solutions

Error: Entry ID cannot be empty

  • Solution: Provide a valid Entry ID obtained from the Get Mail or Search Mail node's result. Access it via email.entryId.

Error: Store ID cannot be empty

  • Solution: Provide a valid Store ID obtained from the Get Mail or Search Mail node's result. Access it via email.storeId.

Error: Directory Path cannot be empty

  • Solution: Specify a valid directory path where attachments should be saved.

Error: Directory does not exist at the specified path

  • Solution:
    • Create the directory before running Save Attachments
    • Use File System package's Create Directory node
    • Verify the path is correct and accessible

Error: No attachments found in the specified email

  • Solution:
    • Verify the email actually has attachments
    • Check that you're using the correct Entry ID
    • Consider using Search Mail with [HasAttachments] = true filter to find only emails with attachments

Attachments saved but files are empty or corrupted

  • Solution:
    • Verify Microsoft Outlook is working properly
    • Check disk space on the target drive
    • Ensure the email hasn't been corrupted
    • Try opening the attachment in Outlook manually first

Cannot save attachments - Outlook security warning

  • Solution: This may be an Outlook security feature. Ensure:
    • Outlook is configured to allow programmatic access
    • Your antivirus isn't blocking the operation
    • You have appropriate permissions

Saved files have different names than expected

  • Solution: Outlook attachments are saved with their original filenames. If you need custom naming:
    • Save attachments first
    • Use File System package to list the directory
    • Rename files as needed using File System Rename node

Disk space issues when saving many attachments

  • Solution:
    • Monitor available disk space
    • Implement cleanup routines to delete old attachments
    • Consider compressing saved files
    • Archive to cloud storage if needed

Performance issues with large attachments

  • Solution:
    • Process attachments in smaller batches
    • Save to local SSD rather than network drives for better performance
    • Consider running during off-peak hours for scheduled automations