PyObjC MailKit Framework

12.1 · active · verified Tue Apr 14

The `pyobjc-framework-mailkit` library provides Python wrappers for the macOS MailKit framework. MailKit allows developers to extend the functionality of Apple Mail, primarily through Mail app extensions. As part of the larger PyObjC project, it enables Python applications to interact with native macOS Objective-C APIs. The current version is 12.1, with releases typically tied to macOS SDK updates and Python version compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic Objective-C object interaction using `Foundation.NSString` via PyObjC. While it doesn't directly use a MailKit class, it shows the general pattern for importing and interacting with Objective-C frameworks. MailKit classes, such as `MKMailExtension`, are typically instantiated and used within the specific context of a Mail app extension on macOS, and not as standalone Python scripts.

import objc
from Foundation import NSString, NSLog

# This example demonstrates basic PyObjC usage. MailKit classes
# (e.g., MKMailExtension) primarily function within a Mail app extension
# context on macOS, not as standalone scripts.

try:
    # Create a Python string
    python_string = "Hello from PyObjC MailKit environment!"

    # Convert it to an Objective-C NSString using a convenience method
    objc_string = NSString.stringWithString_(python_string)

    # Log the Objective-C string using NSLog
    NSLog("%@", objc_string)

    print(f"Python string: {python_string} (type: {type(python_string)})")
    print(f"Objective-C NSString: {objc_string} (type: {type(objc_string)})")
    print(f"Length of NSString: {objc_string.length()}")

    # Attempting to import a MailKit class to show the pattern
    # from MailKit import MKMailExtension # This import might fail if not specifically linked or on older macOS
    # if 'MKMailExtension' in globals():
    #     print("MKMailExtension class is available (but requires Mail extension context for use).")
    # else:
    #     print("MKMailExtension class not directly available in this standalone context (expected).")

except Exception as e:
    print(f"An error occurred during PyObjC interaction: {e}")
    print("Ensure you are on macOS and the PyObjC environment is correctly set up.")

view raw JSON →