Skip to main content

A Python package to interact with both on-premises and Office 365 Exchange Web Services

Project description

py-ews

Documentation Status

.______   ____    ____       ___________    __    ____   _______.
|   _  \  \   \  /   /      |   ____\   \  /  \  /   /  /       |
|  |_)  |  \   \/   / ______|  |__   \   \/    \/   /  |   (----`
|   ___/    \_    _/ |______|   __|   \            /    \   \    
|  |          |  |          |  |____   \    /\    / .----)   |   
| _|          |__|          |_______|   \__/  \__/  |_______/    

A Python package to interact with Exchange Web Services

py-ews is a cross platform python package to interact with both Exchange 2010 to 2019 on-premises and Exchange Online (Office 365). This package will wrap all Exchange Web Service endpoints, but currently is focused on providing eDiscovery endpoints.

py-ews has the following notable features in it's current release:

  • Autodiscover support
  • Delegation support
  • Impersonation support
  • Retrieve all mailboxes that can be searched based on credentials provided
  • Search a list of (or single) mailboxes in your Exchange environment using all supported search attributes
  • Delete email items from mailboxes in your Exchange environment
  • Retrieve mailbox inbox rules for a specific account

Currently this package supports the following ServiceEndpoints:

  • Autodiscover
  • DeleteItem
  • GetInboxRules
  • GetSearchableMailboxes
  • ResolveNames
  • SearchMailboxes

Installation

OS X & Linux:

pip install py-ews

Windows:

pip install py-ews

Usage example

The first step in using py-ews is that you need to create a UserConfiguration object. Think of this as all the connection information for Exchange Web Services. An example of creating a UserConfiguration object using Office 365 Autodiscover is:

from pyews import UserConfiguration

userconfig = UserConfiguration(
      'myaccount@company.com',
      'Password1234'
)

If you would like to use an alternative Autodiscover endpoint (or any alternative endpoint) then please provide one using the endpoint named parameter:

from pyews import UserConfiguration

userconfig = UserConfiguration(
   'myaccount@company.com',
   'Password1234',
   endpoint='https://outlook.office365.com/autodiscover/autodiscover.svc'
)

For more information about creating a UserConfiguration object, please see the full documentation on our ReadTheDocs page.

Now that you have a UserConfiguration object, we can now use a ServiceEndpoint. This example will demonstrate how you can identify which mailboxes you have access to by using the GetSearchableMailboxes EWS endpoint.

Once you have identified a list of mailbox reference ids, then you can begin searching all of those mailboxes by using the SearchMailboxes EWS endpoint.

The returned results will then be deleted (moved to Deleted Items folder) from Exchange using the DeleteItem EWS endpoint.

from pyews import UserConfiguration

userconfig = UserConfiguration(
      'myaccount@company.com',
      'Password1234'
)

# get searchable mailboxes based on your accounts permissions
referenceid_list = []
for mailbox in GetSearchableMailboxes(userconfig).response:
      referenceid_list.append(mailbox['ReferenceId'])

# let's search all the referenceid_list items
messages_found = []
for search in SearchMailboxes('subject:account', userconfig, referenceid_list).response:
      messages_found.append(search['MessageId'])
      # we can print the results first if we want
      print(search['Subject'])
      print(search['MessageId'])
      print(search['Sender'])
      print(search['ToRecipients'])
      print(search['CreatedTime'])
      print(search['ReceivedTime'])
      #etc.

# if we wanted to now delete a specific message then we would call the DeleteItem 
# class like this but we can also pass in the entire messages_found list
deleted_message_response = DeleteItem(messages_found[2], userconfig).response

print(deleted_message_response)

The following is an example of the output returned when calling the above code:

YOUR ACCOUNT IS ABOUT TO EXPIRE! UPGRADE NOW!!!
AAMkAGZjOTlkOWExLTM2MDEtNGI3MS0..............
Josh Rickard
Research
2019-02-28T18:28:36Z
2019-02-28T18:28:36Z
Upgrade Your Account!
AAMkADAyNTZhNmMyLWNmZTctNDIyZC0..............
Josh Rickard
Josh Rickard 
2019-01-24T18:41:11Z
2019-01-24T18:41:11Z
New or modified user account information
AAMkAGZjOTlkOWExLTM2MDEtNGI3MS04.............. 
Microsoft Online Services Team
Research
2019-01-24T18:38:06Z
2019-01-24T18:38:06Z
[{'MessageText': 'Succesfull'}]

For more examples and usage, please refer to the [Wiki][wiki].

Development setup

I have provided a Dockerfile with all the dependencies and it is currently calling bin\pyews_test.py. If you want to test new features, I recommend that you use this Dockerfile instead of a virtualenv. You can call the following to build a new container, but keep the dependencies unless they have changed in your requirements.txt or any other changes to the Dockerfile.

docker build --force-rm -t pyews .

To run the container, use the following:

docker run pyews

Release History

  • 1.0.0
    • Initial release of py-ews to PyPi
  • 1.0.1
    • Updating Documentation with new reference links

Meta

Josh Rickard – @MSAdministratorrickardja@live.com

Distributed under the MIT license. See LICENSE for more information.

Contributing

  1. Fork it (https://github.com/swimlane/pyews/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-ews-1.0.7.tar.gz (18.7 kB view details)

Uploaded Source

Built Distributions

py_ews-1.0.7-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

py_ews-1.0.7-py2-none-any.whl (27.3 kB view details)

Uploaded Python 2

File details

Details for the file py-ews-1.0.7.tar.gz.

File metadata

  • Download URL: py-ews-1.0.7.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for py-ews-1.0.7.tar.gz
Algorithm Hash digest
SHA256 64e8dc3eb189fb7db72fd9256796b6cd7c607ed32060942fbab9ea42e6a08271
MD5 9ef9f3ca6944e34fa94aa0cdad7c5cd6
BLAKE2b-256 e798b12e7cbdfc3885ec61cfc55e2a634d65499189c9fd3bd4f46c7e9a2e2821

See more details on using hashes here.

File details

Details for the file py_ews-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: py_ews-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for py_ews-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a62ddde15b4e569486cd7f46df235cf6fee35e2b84dd64ab09c3e98923fdc70d
MD5 971a3b3f6e069b842cdb488cbbd8366a
BLAKE2b-256 17c4b9142a5db7782bc7e6362638a2d00e45d554b3b19176d852d690ebb76d4b

See more details on using hashes here.

File details

Details for the file py_ews-1.0.7-py2-none-any.whl.

File metadata

  • Download URL: py_ews-1.0.7-py2-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for py_ews-1.0.7-py2-none-any.whl
Algorithm Hash digest
SHA256 735118b4242783255a4432f065bd59a694c1770388000d930c8542237a2e75f5
MD5 a6e1a20d29481a1b4f05f48b3a6cac8b
BLAKE2b-256 b0c477d49d67551b1be3fd0b384f4e31934a334269ae5795838b20532227d967

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page