🔍 Code Extractor

class ReferenceAttachment

Maturity: 39

A class representing a reference attachment that links to files stored on OneDrive for Business or other supported cloud storage locations, attached to Outlook events, messages, or posts.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/reference.py
Lines:
4 - 6
Complexity:
simple

Purpose

ReferenceAttachment extends the base Attachment class to specifically handle cloud-based file references rather than embedded file content. It is used in Microsoft 365/Outlook integrations to attach links to files stored in cloud drives (like OneDrive for Business, SharePoint) to emails, calendar events, or posts. This allows sharing files without embedding them directly, reducing message size and enabling real-time collaboration on the referenced documents.

Source Code

class ReferenceAttachment(Attachment):
    """A link to a file (such as a text file or Word document) on a OneDrive for Business cloud drive or other
    supported storage locations, attached to an event, message, or post."""

Parameters

Name Type Default Kind
bases Attachment -

Parameter Details

__init__: The constructor parameters are inherited from the parent Attachment class. Typically includes properties like name (file name), contentType (MIME type), and reference-specific properties such as sourceUrl (link to the file), providerType (storage provider), and permission (access permissions).

Return Value

Instantiation returns a ReferenceAttachment object that represents a cloud file reference. The object inherits all methods and properties from the Attachment base class, allowing it to be used wherever an Attachment is expected in the Office365 API context.

Class Interface

Methods

__init__()

Purpose: Initializes a new ReferenceAttachment instance, inheriting from the Attachment base class

Returns: A new ReferenceAttachment instance

Attributes

Name Type Description Scope
name str The display name of the attachment (inherited from Attachment) instance
contentType str The MIME type of the referenced file (inherited from Attachment) instance
sourceUrl str The URL pointing to the file in cloud storage instance
providerType str The type of storage provider (e.g., 'oneDriveConsumer', 'oneDriveBusiness', 'dropbox') instance
permission str The permission level for accessing the referenced file (e.g., 'view', 'edit', 'anonymousView', 'anonymousEdit') instance
isFolder bool Indicates whether the reference points to a folder rather than a file instance
thumbnailUrl str URL to a thumbnail image of the referenced file instance

Dependencies

  • office365

Required Imports

from office365.outlook.mail.attachments.reference_attachment import ReferenceAttachment

Usage Example

from office365.outlook.mail.attachments.reference_attachment import ReferenceAttachment
from office365.runtime.auth.client_credential import ClientCredential
from office365.graph_client import GraphClient

# Authenticate
credentials = ClientCredential('client_id', 'client_secret')
client = GraphClient(credentials)

# Create a reference attachment
attachment = ReferenceAttachment()
attachment.name = 'Project Plan.docx'
attachment.sourceUrl = 'https://contoso.sharepoint.com/sites/team/Shared%20Documents/Project%20Plan.docx'
attachment.providerType = 'oneDriveConsumer'
attachment.permission = 'view'

# Attach to a message
message = client.me.messages.add(
    subject='Project Update',
    body={'content': 'Please review the attached document'}
)
message.attachments.add(attachment)
client.execute_query()

Best Practices

  • Ensure the referenced file URL is accessible to the intended recipients with appropriate permissions
  • Use reference attachments instead of file attachments for large files to reduce message size and enable collaboration
  • Verify that the providerType matches the actual storage location (e.g., 'oneDriveConsumer', 'oneDriveBusiness', 'dropbox')
  • Set appropriate permission levels ('view', 'edit', 'anonymousView', 'anonymousEdit') based on security requirements
  • The sourceUrl must be a valid, accessible URL to the cloud-stored file
  • Reference attachments require that recipients have access to the storage location; consider using file attachments for external recipients without access
  • This class inherits from Attachment, so all base class methods and properties are available

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class FileAttachment 71.3% similar

    Represents a file attachment (text file, Word document, etc.) associated with an Outlook user event, message, or post, providing access to file metadata and content.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/file.py
  • class ItemAttachment 67.7% similar

    A class representing an attachment that contains an Outlook item (contact, event, or message) attached to a user event, message, or post.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/item.py
  • class Attachment 67.4% similar

    Represents a file or item (contact, event, or message) attached to an event or message in Office 365, providing methods to download and access attachment content and metadata.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/attachment.py
  • class AttachmentItem 60.4% similar

    A data class representing metadata attributes of an attachment item, including its type, name, and size.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/attachment_item.py
  • class AttachmentBase 60.0% similar

    An abstract base class representing an attachment that can be added to a todoTask, providing properties for attachment metadata such as content type, size, name, and modification timestamp.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/todo/attachments/base.py
← Back to Browse