Skip to main content

orbitra.commons.email.client

Functions

get_email_client

Get the OrbitraEmailClient instance. Args:
  • environment: Environment to use (“prod” or “dev”). Defaults to “prod”.
  • credential: Synchronous Azure credential for API operations.
  • email_address: Optional email address to use for app-only auth URL resolution.
Returns:
  • An instance of the OrbitraEmailClient class.

Classes

OrbitraEmailClient

OrbitraEmailClient for interacting with email functionality using Microsoft Graph API. Methods:

get_email

Get detailed information about a specific email by its ID. Args:
  • email_id: The ID of the email to retrieve.
  • include_attachments: Whether to include attachment details in the response. Defaults to True.
Returns:
  • An object containing detailed information about the email. See :class:orbitra.commons.email.models.EmailDetail.
Raises:
  • Exception: If retrieving the email fails or attachments fails.

list_emails

List emails in the specified folder with optional filtering. Args:
  • folder: The email folder to list emails from (e.g., “inbox”, “sentitems”, “junkemail”). Defaults to “inbox”.
  • top: The maximum number of emails to return. Defaults to 25.
  • state: Filter emails by their state. Options are Literal[“processing”, “processed”, “error”, “none”]. Defaults to None.
  • is_read: Filter emails by read/unread status. Defaults to None.
  • received_after: Filter emails received after this date/time (ISO 8601 format). Defaults to None.
  • received_before: Filter emails received before this date/time (ISO 8601 format). Defaults to None.
  • subject_contains: Filter emails where the subject contains this string. Defaults to None.
  • from_contains: Filter emails where the sender’s email address contains this string. Defaults to None.
Returns:
  • list[EmailDetail]: A list of email details matching the specified criteria. See :class:orbitra.commons.email.models.EmailDetail.
Raises:
  • Exception: If listing emails fails.

send_email

Send an email via Microsoft Graph API. Args:
  • subject: The subject of the email.
  • body: The body of the email.
  • to: The list of recipients.
  • cc: The list of CC recipients. Defaults to None.
  • bcc: The list of BCC recipients. Defaults to None.
  • attachments: The list of attachments. Each attachment is a dict with ‘filename’ and ‘content’ keys. Defaults to None.
  • body_format: The format of the email body. Defaults to “html”.
  • reply_to: The list of reply-to addresses. Defaults to None.
Raises:
  • Exception: If email sending fails.
Examples: Example usage:
Example with csv attachment:
Example with multiple attachments:
Example with inline image:

set_email_processing_state

Set the state of an email by updating its categories. Args:
  • email_id: The ID of the email to update.
  • state: The state to set for the email. Options are Literal[“processing”, “processed”, “error”, “none”].
Raises:
  • Exception: If updating the email state fails.