0
# Advanced Features
1
2
Advanced functionality including bulk operations, extended properties, impersonation, and low-level EWS service access for complex Exchange operations.
3
4
## Capabilities
5
6
### Bulk Operations
7
8
```python { .api }
9
def bulk_create(account: Account, items: list, chunk_size: int = None) -> list:
10
"""Create multiple items efficiently."""
11
12
def bulk_update(account: Account, items: list, chunk_size: int = None) -> list:
13
"""Update multiple items efficiently."""
14
15
def bulk_delete(account: Account, items: list, chunk_size: int = None, delete_type: str = 'MoveToDeletedItems') -> None:
16
"""Delete multiple items efficiently."""
17
18
def export_items(account: Account, items: list) -> list:
19
"""Export items to their native EWS format."""
20
21
def upload_items(account: Account, data: list, folder: Folder) -> list:
22
"""Upload items from their native EWS format."""
23
```
24
25
### Extended Properties
26
27
```python { .api }
28
class ExtendedProperty:
29
def __init__(
30
self,
31
distinguished_property_set_id: str = None,
32
property_set_id: str = None,
33
property_tag: int = None,
34
property_name: str = None,
35
property_id: int = None,
36
property_type: str = None
37
):
38
"""Create custom Exchange property."""
39
40
value: any
41
42
# Property set constants
43
COMMON: str = 'Common'
44
PUBLIC_STRINGS: str = 'PublicStrings'
45
APPOINTMENT: str = 'Appointment'
46
MEETING: str = 'Meeting'
47
TASK: str = 'Task'
48
ADDRESS: str = 'Address'
49
```
50
51
### Protocol Configuration
52
53
```python { .api }
54
class BaseProtocol:
55
def __init__(
56
self,
57
config: Configuration,
58
retry_policy: RetryPolicy = None
59
):
60
"""Low-level EWS protocol handler."""
61
62
class FailFast:
63
"""Retry policy that fails immediately on errors."""
64
65
class FaultTolerance:
66
def __init__(self, max_wait: int = 3600):
67
"""Retry policy with fault tolerance."""
68
69
class NoVerifyHTTPAdapter:
70
"""HTTP adapter that skips SSL verification."""
71
72
class TLSClientAuth:
73
def __init__(self, ca_cert: str, cert_file: str, key_file: str):
74
"""TLS client certificate authentication."""
75
```
76
77
### Version Information
78
79
```python { .api }
80
class Version:
81
def __init__(self, build=None):
82
"""Exchange server version information."""
83
84
build: Build
85
api_version: str
86
87
class Build:
88
def __init__(self, major_version: int, minor_version: int, major_build_number: int, minor_build_number: int = 0):
89
"""Exchange server build information."""
90
91
major_version: int
92
minor_version: int
93
major_build_number: int
94
minor_build_number: int
95
96
def __str__(self) -> str:
97
"""String representation of build version."""
98
```
99
100
### Streaming Notifications
101
102
```python { .api }
103
def get_streaming_events(
104
account,
105
subscription_id: str,
106
connection_timeout: int = 30
107
):
108
"""Get streaming notifications for folder changes."""
109
110
def subscribe_to_notifications(
111
account,
112
folders,
113
event_types
114
) -> str:
115
"""Subscribe to folder change notifications."""
116
```
117
118
### Error Handling
119
120
```python { .api }
121
# Base exception classes
122
class EWSError(Exception):
123
"""Base EWS error."""
124
125
class TransportError(EWSError):
126
"""Transport/connection error."""
127
128
class ProtocolError(EWSError):
129
"""EWS protocol error."""
130
131
class ResponseMessageError(EWSError):
132
"""EWS response message error."""
133
134
class UnauthorizedError(EWSError):
135
"""Authentication/authorization error."""
136
137
class RateLimitError(EWSError):
138
"""Rate limiting error."""
139
```
140
141
Usage examples:
142
143
```python
144
from exchangelib import ExtendedProperty, FailFast, bulk_create
145
146
# Use extended properties
147
custom_prop = ExtendedProperty(
148
distinguished_property_set_id=ExtendedProperty.PUBLIC_STRINGS,
149
property_name='CustomField',
150
property_type='String'
151
)
152
153
message = Message(
154
account=account,
155
subject='Custom Property Test'
156
)
157
message.extended_properties = [custom_prop]
158
custom_prop.value = 'Custom Value'
159
message.save()
160
161
# Bulk operations
162
messages = [
163
Message(account=account, subject=f'Bulk {i}')
164
for i in range(100)
165
]
166
created = bulk_create(account, messages)
167
168
# Error handling
169
try:
170
account.inbox.all().count()
171
except UnauthorizedError:
172
print("Authentication failed")
173
except RateLimitError:
174
print("Rate limited, retry later")
175
```