### Managing Folders Source: https://pyoutlook.readthedocs.io/en/latest/quickstart.html Examples of retrieving all folders, getting a specific folder, creating a child folder, and renaming a folder. ```python from pyOutlook import OutlookAccount account = OutlookAccount('token') # Get all folders folders = account.folders.all() for folder in folders: print(f'{folder.name}: {folder.unread_count} unread') # Get a specific folder by ID or well-known name inbox_folder = account.folders.get('Inbox') custom_folder = account.folders.get('folder_id_here') # Folder operations are methods on the Folder object subfolder = inbox_folder.create_child_folder('Archive 2024') inbox_folder.rename('My Inbox') ``` -------------------------------- ### Instantiation Example Source: https://pyoutlook.readthedocs.io/en/latest/quickstart.html Instantiate the OutlookAccount class with an access token. ```python from pyOutlook import OutlookAccount account_one = OutlookAccount('token 1') account_two = OutlookAccount('token 2') ``` -------------------------------- ### Retrieving Emails Source: https://pyoutlook.readthedocs.io/en/latest/quickstart.html Examples of retrieving emails from the inbox, all messages (paginated), a specific message by ID, and messages from a specific folder. ```python # Get inbox messages inbox = account.inbox() inbox[0].body >>> 'A very fine body' # Get all messages (paginated) messages = account.messages.all() messages = account.messages.all(page=2) # Get page 2 # Get a specific message by ID message = account.messages.get('message_id') print(message.subject) # Get messages from a specific folder drafts = account.messages.from_folder('Drafts') ``` -------------------------------- ### Sending Email with Attachments Source: https://pyoutlook.readthedocs.io/en/latest/quickstart.html Send an email with attachments by creating Attachment objects. ```python import base64 from pyOutlook import OutlookAccount, Attachment account = OutlookAccount('token') # Read file and encode to base64 with open('document.pdf', 'rb') as f: content = base64.b64encode(f.read()).decode('utf-8') attachment = Attachment('document.pdf', content, content_type='application/pdf') account.messages.send( subject='Document Attached', body='
Please find the document attached.
', to=['recipient@domain.com'], attachments=[attachment] ) ``` -------------------------------- ### Install using pip Source: https://pyoutlook.readthedocs.io/en/latest/installation.html The recommended way to install pyOutlook is using pip. ```bash pip install pyOutlook ``` -------------------------------- ### Sending Simple Email Source: https://pyoutlook.readthedocs.io/en/latest/quickstart.html Send a simple email using the send method. ```python from pyOutlook import OutlookAccount, Contact account = OutlookAccount('token') # Send a simple email account.messages.send( subject='Hey there', body="I'm sending an email through Python.Hi there
', to=['user1@example.com', 'user2@example.com'] ) # Using Contact objects account.messages.send( subject='Hello', body='Hi there
', to=[ Contact('user1@example.com', name='User One'), Contact('user2@example.com', name='User Two') ] ) ``` -------------------------------- ### Accessing Sender Information Source: https://pyoutlook.readthedocs.io/en/latest/_sources/quickstart.rst.txt Access the sender's name and email from a Message object. ```python message = account.inbox()[0] message.sender.name >>> 'Dude' message.sender.email >>> 'dude@example.com' ``` -------------------------------- ### Accessing Inbox Messages Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Example of how to get the Inbox folder and retrieve its messages. ```python inbox = account.folders.get('Inbox') messages = inbox.messages() ``` -------------------------------- ### Sending Email with Contacts and CC/BCC Source: https://pyoutlook.readthedocs.io/en/latest/quickstart.html Send an email with Contact objects for recipients and include CC/BCC recipients. ```python from pyOutlook import OutlookAccount, Contact account = OutlookAccount('token') # Send with Contact objects and CC/BCC account.messages.send( subject='Project Update', body='Here is the latest update on the project.
', to=[Contact('colleague@domain.com', name='Colleague Name')], cc=['manager@domain.com'], bcc=['archive@domain.com'] ) ``` -------------------------------- ### Sending Emails with String or Contact Recipients Source: https://pyoutlook.readthedocs.io/en/latest/_sources/quickstart.rst.txt Demonstrates sending emails using either a list of email strings or a list of Contact objects. ```python from pyOutlook import Contact # Using email strings account.messages.send( subject='Hello', body='Hi there
', to=['user1@example.com', 'user2@example.com'] ) # Using Contact objects account.messages.send( subject='Hello', body='Hi there
', to=( Contact('user1@example.com', name='User One'), Contact('user2@example.com', name='User Two') ) ) ``` -------------------------------- ### Get Subfolders Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Retrieves all immediate child folders of the current folder. ```python get_subfolders() → list[Folder] ``` -------------------------------- ### Create and send a new message Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Example of creating a new Message object and sending it. ```python # Create and send a new message message = Message(account, body='Hello!
', subject='Greetings', to_recipients=[Contact('user@example.com')]) message.send() ``` -------------------------------- ### Listing Folders and Unread Counts Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Example of how to retrieve all folders for an account and print their names and unread message counts. ```python # Get all folders folders = account.folders.all() for folder in folders: print(f'{folder.name}: {folder.unread_count} unread') ``` -------------------------------- ### Iterate and mark messages as read Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html This example shows how to iterate through messages in the inbox and mark each message as read. ```python for msg in account.inbox(): print(msg.subject) msg.is_read = True # Mark as read ``` -------------------------------- ### Sending a Message Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Example of how to send an email message using the MessageService, including recipients, subject, body, and CC. ```python account.messages.send( subject='Meeting Tomorrow', body='Let\'s meet at 10am.
', to=['colleague@example.com'], cc=[Contact('manager@example.com', name='Manager')] ) ``` -------------------------------- ### Forward Message with Comment Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Example of forwarding an email with an added comment. ```python message.forward('user@example.com', forward_comment='FYI') ``` -------------------------------- ### Forward a message to recipients Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Examples of forwarding a message to single or multiple recipients. ```python # Single recipient as string message.forward('user@example.com') # Multiple recipients as list message.forward(['user1@example.com', 'user2@example.com']) ``` -------------------------------- ### FolderService Get Folder by ID Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Retrieves a specific folder by its ID or a well-known name. ```python get(_folder_id : str_) → Folder ``` -------------------------------- ### Set auto-reply with different internal/external messages Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html This example demonstrates scheduling an auto-reply with distinct messages for internal and external recipients, and specifies the audience and time window. ```python from datetime import datetime # Enable auto-reply for everyone account.set_auto_reply('I am currently out of office.') # Schedule auto-reply with different internal/external messages account.set_auto_reply( message='Internal: I am on vacation.', external_message='Thank you for your email. I am currently unavailable.', status=account.AutoReplyStatus.SCHEDULED, start=datetime(2024, 12, 20), end=datetime(2024, 12, 31), audience=account.AutoReplyAudience.ALL ) ``` -------------------------------- ### API representation of an attachment Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Demonstrates how to get the API-formatted dictionary representation of an attachment object, which is expected by the Microsoft Graph API. ```Python attachment = Attachment('file.pdf', 'base64content...') api_format = attachment.api_representation() # {'@odata.type': '#microsoft.graph.fileAttachment', 'name': 'file.pdf', ...} ``` -------------------------------- ### Creating a contact for sending Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Demonstrates how to create a Contact object for sending an email, including setting the display name. ```Python # Creating a contact for sending recipient = Contact('user@example.com', name='John Doe') # Using with the API payload = dict(recipient) # Converts to API format ``` -------------------------------- ### OutlookAccount Initialization and Usage Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Demonstrates how to initialize an OutlookAccount object with an access token and how to access inbox messages and all folders. ```python # Initialize with an OAuth token account = OutlookAccount('your-access-token') # Access inbox messages inbox_messages = account.inbox() # Get all folders all_folders = account.folders.all() ``` -------------------------------- ### Creating an attachment for sending Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Shows how to create an Attachment object for sending an email, including reading a file, encoding its content to base64, and specifying the content type. ```Python # Creating an attachment for sending import base64 with open('document.pdf', 'rb') as f: content = base64.b64encode(f.read()).decode('utf-8') attachment = Attachment('document.pdf', content, content_type='application/pdf') ``` -------------------------------- ### Create Child Folder Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Creates a new subfolder within the current folder. ```python create_child_folder(_folder_name : str_) → Folder ``` -------------------------------- ### Send a basic email Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html This snippet shows how to send a simple email with a subject, body, and recipient. ```python account.messages.send( subject='Hello', body='Hello World!
', to=['recipient@example.com'] ) ``` -------------------------------- ### FolderService Class Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Service class for creating Folder instances from API responses. ```python class _pyOutlook.services.folder.FolderService(_account : OutlookAccount_) ``` -------------------------------- ### FolderService All Folders Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Retrieves all folders associated with the account. ```python all() → list[Folder] ``` -------------------------------- ### Accessing content from a retrieved attachment Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Illustrates how to access and save the binary content of a retrieved attachment to a local file. ```Python # Accessing content from a retrieved attachment with open('downloaded.pdf', 'wb') as f: f.write(attachment.bytes) ``` -------------------------------- ### Copy Folder Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Copies a folder into a specified destination folder. ```python copy_into(_destination_folder : Folder_) → Folder ``` -------------------------------- ### Move Folder Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Moves the current folder to become a child of a different folder. ```python move_into(_destination_folder : Folder_) → Folder ``` -------------------------------- ### FolderService Account Property Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html The associated OutlookAccount for the FolderService. ```python account _: OutlookAccount_ ``` -------------------------------- ### Folder Headers Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Accesses the HTTP headers used for API requests related to the folder. ```python _property _headers _: dict_ ``` -------------------------------- ### Rename Folder Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Renames the current folder to a new specified name. ```python rename(_new_folder_name : str_) → Folder ``` -------------------------------- ### Delete Folder Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Deletes the current folder and all its contents. ```python delete() → None ``` -------------------------------- ### Retrieve Messages Source: https://pyoutlook.readthedocs.io/en/latest/pyOutlook.html Retrieves messages contained within the current folder. ```python messages() → list ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.