ews-cpp  0.9
ews-cpp Documentation

ews-cpp

A C++11 header-only library for Microsoft Exchange Web Services.

Example

You can find a couple of small executable examples in the examples/ folder.

As an appetizer, this is how it looks when you create and send an email message with ews-cpp:

#include <ews/ews.hpp>
#include <exception>
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
int main() {
try {
auto service = ews::service("https://example.com/ews/Exchange.asmx",
"ACME",
"myuser",
"mysecret");
auto message = ews::message();
message.set_subject("Test mail from outer space");
std::vector<ews::mailbox> recipients{ ews::mailbox("president@example.com") };
message.set_to_recipients(recipients);
auto text = ews::body("ようこそ (Welcome!)\n\nThis is a test.\n");
message.set_body(text);
} catch (std::exception& exc) {
std::cout << exc.what() << std::endl;
}
return 0;
}

Documentation

We host automatically generated API documentation here: otris.github.io/ews-cpp.

Overview

EWS is an API that third-party programmers can use to communicate with Microsoft Exchange Server. The API exists since Exchange Server 2007 and is continuously up-dated by Microsoft and present in the latest iteration of the product, Exchange Server 2016.

This library provides a native and platform-independent way to use EWS in your C++ application.

Supported Operations and Elements

Supported Authentication Schemes

Note: Kerberos is currently not supported but its on the TODO list.

OAuth2

Supported Compilers

Supported Operating Systems

Supported Microsoft Exchange Server Versions

However, our goal is to support all Exchange Server versions since 2007.

Run-time Dependencies

The only thing you need for ews-cpp to run is libcurl.

Dev Dependencies

If you want to hack on ews-cpp itself you additionally need

Note Windows Users

You can obtain an up-to-date and easy-to-use binary distribution of libcurl from here: confusedbycode.com/curl

Additionally, you probably need to tell CMake where to find it. Just set CMAKE_PREFIX_PATH to the path where you installed libcurl (e.g. C:\Program Files\cURL) and re-configure.

You can also use the Windows batch script provided in scripts\build-curl.bat to download and compile libcurl for your particular version of Visual Studio.

Source Code

ews-cpp's source code is available as a Git repository. To obtain it, type:

1 git clone --recursive https://github.com/otris/ews-cpp.git

Building

Linux

The library is header-only. So there is no need to build anything. Just copy the include/ews/ directory wherever you may like.

To build the accompanied tests with debugging symbols and Address Sanitizer enabled do something like this:

1 cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON /path/to/source
2 make

Type make edit_cache to see all configuration options. make help shows you all available targets.

Windows

To build the tests and examples on Windows you can use cmake-gui. For more see: https://cmake.org/runningcmake/

If you do not want to use any GUI to compile the examples and tests you could do something like this with the Windows cmd.exe command prompt:

1 set PATH=%PATH%;C:\Program Files (x86)\CMake\bin
2 mkdir builddir
3 cd builddir
4 cmake -G "Visual Studio 14 2015 Win64" ^
5  -DCURL_LIBRARY="C:\Program Files\cURL\7.49.1\win64-debug\lib\libcurl_debug.lib" ^
6  -DCURL_INCLUDE_DIR="C:\Program Files\cURL\7.49.1\win64-debug\include" ^
7  C:\path\to\source
8 cmake --build .

Make sure to choose the right generator for your environment.

API Docs

Use the doc target to create the API documentation with Doxygen. Type:

1 make doc
2 open html/index.html

Test Suite

In order to run individual examples or the test suite export following environment variables like this:

1 export EWS_TEST_DOMAIN="DUCKBURG"
2 export EWS_TEST_USERNAME="mickey"
3 export EWS_TEST_PASSWORD="pluto"
4 export EWS_TEST_URI"https://hire-a-detective.com/ews/Exchange.asmx"

Be sure to change the values to an actual account on some Exchange server that you can use for testing. Do not run the tests on your own production account.

Once you've build the project, you can execute the tests with:

1 ./tests --assets=/path/to/source/tests/assets

If you do not have any Exchange server available for testing you can run a subset of the tests that do not require a running server like this:

1 EWS_TEST_DOMAIN="" EWS_TEST_USERNAME="" EWS_TEST_PASSWORD="" EWS_TEST_URI="" ./tests \
2  --assets=$HOME/src/ews-cpp/tests/assets \
3  --gtest_filter=Offline\*.\*

Design Notes

ews-cpp is written in a "modern C++" way:

API

Just add:

#include <ews/ews.hpp>

to your include directives and you are good to go.

Take a look at the examples/ directory to get an idea of how the API feels. ews-cpp is a thin wrapper around Microsoft's EWS API. You will need to refer to the EWS reference for Exchange for all available parameters to pass and all available attributes on items. From 10.000ft it looks like this:

You have items and you have the service. You use the service whenever you want to talk to the Exchange server.

Please note one important caveat though. ews-cpp's API is designed to be "blocking". This means whenever you call one of the service's member functions to talk to an Exchange server that call blocks until it receives a request from the server. And that may, well, just take forever (actually until a timeout is reached). You need to keep this in mind in order to not block your main or UI thread.

Implications of this design choice

Pros:

Cons:

More EWS Resources

Legal Notice

ews-cpp is developed by otris software AG and was initially released to the public in July 2016. It is licensed under the Apache License, Version 2.0 (see LICENSE file).

For more information about otris software AG visit our website otris.de or our Open Source repositories at github.com/otris.