Skip to main content

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

Project description

Welcome to py-ews's documentation!


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



    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.

Features

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
  • Find additional hidden inbox rules for a specified account

Currently this package supports the following endpoint's:

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 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.

Now that you have a UserConfiguration object, we can now use any of the available service endpoints. 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
from pyews import GetSearchableMailboxes
from pyews import SearchMailboxes
from pyews import DeleteItem

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

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

# let's search all the referenceid_list items
messages_found = []
for search in SearchMailboxes(userconfig).run('subject:account', referenceid_list):
      messages_found.append(search['id'])
      # we can print the results first if we want
      print(search['subject'])
      print(search['id'])
      print(search['sender'])
      print(search['to_recipients'])
      print(search['created_time'])
      print(search['received_time'])
      #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(userconfig).run(messages_found[2])

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 individual class documentation

Development setup

I have provided a Dockerfile with all the dependencies and it is currently calling test.py. If you want to test new features, I recommend that you use this Dockerfile. 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

I am new to Unit Testing, but I am working on that as time permits. If you would like to help, I wouldn't be sad about it. :)

Release History

  • 1.0.0
    • Initial release of py-ews and it is still considered a work in progress
  • 2.0.0
    • Revamped logic and overhauled all endpoints and classes

Meta

Josh Rickard – @MSAdministrator

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
.. toctree::
   :maxdepth: 2
   :caption: Contents:

   services/root
   configuration/root
   utils/root

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-2.0.3.tar.gz (17.3 kB view details)

Uploaded Source

Built Distributions

py_ews-2.0.3-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

py_ews-2.0.3-py2-none-any.whl (29.2 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: py-ews-2.0.3.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for py-ews-2.0.3.tar.gz
Algorithm Hash digest
SHA256 59234aefdcddecb82b4bf19429b3c692d7469979d32b596a287e4a885dd516ed
MD5 60b51882d1e0430fbb05b4632dc52aba
BLAKE2b-256 401e65b3f8a72c87bbb7b8b7d07d814d28304aa03d7e52cd1fabbc7c3e2b7444

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ews-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for py_ews-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0b7301d86a341417ac3dfef5f3ac88268776a97d450d88ba0616ec6d59849530
MD5 441110a465040855593b78f646b08b2c
BLAKE2b-256 ba104f89b42f1b10f9969754c6b0f6b5cfbd22c962dea99f9ee842197dca2b95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ews-2.0.3-py2-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for py_ews-2.0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 eb3dc0326cde24e46ba76b25e2fc7ee2c1d6444b3140d1b8715492e595f89f51
MD5 bfe1b554499a01327f1bc9aa5ddb98f9
BLAKE2b-256 f12d0cbf0de8afafd3451ed5a4a5d52d3ca31eb950ab07218dc54925dbfac227

See more details on using hashes here.

Supported by

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