示例#1
0
 public function testWithUsernameAndPassword()
 {
     //Create our expected item, get our class to build our item, then compare
     $expected = ExchangeWebServices::fromUsernameAndPassword('test.com', 'username', 'password', ['version' => ExchangeWebServices::VERSION_2010]);
     $client = API::withUsernameAndPassword('test.com', 'username', 'password');
     $actual = $client->getClient();
     $ntlmSoapReflection = new \ReflectionClass(API\NTLMSoapClient::class);
     $reflectedProp = $ntlmSoapReflection->getProperty('auth');
     $reflectedProp->setAccessible(true);
     $this->assertEquals($reflectedProp->getValue($expected->getClient()), $reflectedProp->getValue($actual->getClient()));
 }
示例#2
0
 /**
  * @param string $email
  * @param string $password
  * @param string $username
  */
 protected function newAPI($email, $password, $username = null, $options = [])
 {
     $options = array_replace_recursive(['httpPlayback' => ['mode' => null]], $options);
     $this->httpPlayback = Factory::getInstance($options['httpPlayback']);
     if (!$username) {
         $username = $email;
     }
     $settings = $this->discover($email, $password, $username);
     if (!$settings) {
         throw new AutodiscoverFailed();
     }
     $server = $this->getServerFromResponse($settings);
     $version = $this->getServerVersionFromResponse($settings);
     if (!$server) {
         throw new AutodiscoverFailed();
     }
     $options = [];
     if ($version) {
         $options['version'] = $version;
     }
     return API::withUsernameAndPassword($server, $email, $password, $options);
 }
示例#3
0
<?php

/**
 * Quick Start
 *
 * This file is an example of how to quickly create a Calendar Item without going through the CalendarAPI, to show
 * that you can create items directly
 */
//Include the API
use garethp\ews\API;
use garethp\ews\API\Enumeration;
//Create and build the client
$api = API::withUsernameAndPassword('server', 'username', 'password');
//Get the folder to save the event to
$folder = $api->getFolderByDistinguishedId('calendar');
//Create our event
$item = array('CalendarItem' => array('Start' => (new \DateTime('8:00 AM'))->format('c'), 'Subject' => 'The Event Subject'));
//Set our options
$options = array('SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE, 'SavedItemFolderId' => array('FolderId' => array('Id' => $folder->getFolderId()->getId())));
//Send the request
$items = $api->createItems($item, $options);
示例#4
0
<?php

use garethp\ews\API\Type\ConnectingSIDType;
use garethp\ews\API\Type\ExchangeImpersonation;
//Impersonate an email address
$api = \garethp\ews\API::withUsernameAndPassword('server', 'username', 'password', ['impersonation' => '*****@*****.**']);
//Build your own impersonation
$connectingSID = new ConnectingSIDType();
$connectingSID->setPrincipalName('Some Name');
$connectingSID->setPrimarySmtpAddress('*****@*****.**');
$impersonation = new ExchangeImpersonation();
$impersonation->setConnectingSID($connectingSID);
$api = \garethp\ews\API::withUsernameAndPassword('server', 'username', 'password', ['impersonation' => $impersonation]);
示例#5
0
<?php

include "vendor/autoload.php";
use garethp\ews\API\ExchangeAutodiscover;
use garethp\ews\API\Exception\AutodiscoverFailed;
use garethp\ews\API;
try {
    //API will now be an instance of \garethp\ews\API;
    $api = ExchangeAutodiscover::getAPI('*****@*****.**', 'password');
    $timezoneList = $api->getServerTimezones();
    //You should never run the Autodiscover more than once. It can make between 1 and 5 calls before giving up, or
    //before finding your server, depending on how many different attempts it needs to make. For this reason, you should
    //only ever do it once to find out where your server is located and what version it's running, and then hard code
    //that or store it in a database, or anything other than running Autodiscover again
    $server = $api->getClient()->getServer();
    $version = $api->getClient()->getVersion();
    $api = API::withUsernameAndPassword($server, '*****@*****.**', 'password', ['version' => $version]);
} catch (AutodiscoverFailed $exception) {
    //Autodiscover failed
}
示例#6
0
<?php

require_once "vendor/autoload.php";
use garethp\ews\API\Type;
use garethp\ews\API\Type\CalendarItem;
use garethp\ews\Caster;
use garethp\ews\Test\API\TypeTest;
use garethp\ews\CalendarAPI;
$api = \garethp\ews\API::withUsernameAndPassword('server', 'username', 'password', ['primarySmtpEmailAddress' => '*****@*****.**']);
$api->getFolderByDistinguishedId('inbox');