Skip to Content
DocumentationIntegrationOutlookFetch Email Attachment

Fetch Email Attachment

Retrieves the content of an email attachment from Outlook/Microsoft 365. This action downloads the raw attachment data for processing or storage.

Overview

  • Purpose: Download email attachment content from Outlook messages.
  • Use Cases: Downloading invoice PDFs, extracting document attachments, processing image files, archiving attachments, automated document workflows, compliance and record-keeping.
  • API Method: GET /fetch-attachment
  • Microsoft Graph API: Uses Microsoft Graph /v1.0/me/messages/\{messageId\}/attachments/\{attachmentId\}/$value endpoint.
  • Required Scope: Mail.Read

Required Input Fields

Thread ID: The unique identifier of the email message (message ID in Microsoft Graph terminology).

Attachment ID: The unique identifier of the specific attachment within the message.

Getting Attachment IDs

  • Email Sync: Use the ‘emails’ sync to retrieve email messages with attachment metadata.
  • Attachment Metadata: Each email’s attachments array contains attachment IDs, filenames, MIME types, and sizes.
  • Message ID: The thread ID parameter refers to the message ID from Microsoft Graph (not the conversation ID).
  • Workflow: First sync emails, then use attachment IDs from the sync data to fetch specific attachments.

Output

  • Raw Content: Returns the attachment content as a string (binary data).
  • Format: The data format depends on the attachment type (binary for files, text for documents).
  • Processing: You may need to handle encoding/decoding based on the attachment’s MIME type.

Attachment Processing

  • Binary Files: For PDFs, images, and other binary files, handle as binary data.
  • Text Files: For text-based attachments, the content is returned as text.
  • MIME Type: Use the MIME type from attachment metadata to determine file type and processing method.
  • Filename: Use the filename from attachment metadata for saving the file.
  • Size Limits: Be aware of attachment size limits when processing large files.

Required Permissions

[!IMPORTANT] OAuth Scope: Requires Mail.Read scope for reading emails and attachments.

  • Read-Only: This scope allows reading emails and attachments but not sending or modifying.
  • User Consent: Users must grant permission to read their emails during OAuth flow.

Error Handling

  • Invalid IDs: Returns an error if the message ID or attachment ID doesn’t exist.
  • Permissions: Fails if the user hasn’t granted the required Mail.Read scope.
  • Retry Logic: Automatically retries failed requests up to 3 times.
  • Large Files: Very large attachments may timeout - consider implementing timeout handling.

Common Use Cases

  • Invoice Processing: Download invoice PDFs from emails for automated processing and accounting.
  • Document Archival: Save important document attachments to cloud storage or document management systems.
  • Image Extraction: Extract images from emails for display, processing, or analysis.
  • Data Import: Download CSV or Excel files from emails for data import workflows.
  • Compliance: Archive email attachments for regulatory compliance and record-keeping.
  • Automated Workflows: Trigger actions based on attachment content (e.g., OCR, data extraction).

Tips

[!TIP] First sync emails to get attachment IDs - you can’t fetch attachments without them

[!IMPORTANT] The ‘threadId’ parameter is actually the message ID from Microsoft Graph

[!TIP] Use attachment metadata (filename, MIME type, size) from the email sync for proper file handling

[!WARNING] Check attachment size before fetching to avoid memory issues with large files

[!TIP] Implement error handling for missing or deleted attachments

[!TIP] Store attachment IDs if you need to fetch the same attachment multiple times

[!TIP] Consider caching downloaded attachments to reduce API calls

[!TIP] Use the MIME type to validate file types before processing

[!TIP] For large attachments, implement streaming or chunked processing if possible

[!IMPORTANT] Ensure your OAuth flow requests the Mail.Read scope

[!TIP] Test with various file types (PDF, images, documents) to ensure proper handling

[!TIP] Handle encoding appropriately based on the attachment’s content type

Need help? Have feedback?