How to Read inbox Mails From Exchange Server

In this tutorial i will tell you, how to read inbox folder mail from exchange server.In Earlie post Connect Exchange Server With PHP we have learn how to connect exchange server with PHP, so we will skip those steps.

So Now we have connected exchange server with PHP and going to download all emails and attachments.I am using ews-api to connect Microsoft Exchange 2007 and 2010 Web Services in PHP.

You can also check other recommended tutorial of Exchange Api,

I am assuming you have $ews object as mentioned in earlie post Connect Exchange Server With PHP.

How To Download inbox Mails and Attachments From Exchange Server

Step 1: We will create request object to send api.The request object will have all setting or configuration properties that need to download all emails and attachments.
[code type =php]
$request = new EWSType_FindItemType();
$itemProperties = new EWSType_ItemResponseShapeType();
$itemProperties->BaseShape = EWSType_DefaultShapeNamesType::ID_ONLY;
$itemProperties->BodyType = EWSType_BodyTypeResponseType::BEST;
$request->ItemShape = $itemProperties;

$request->IndexedPageItemView = new EWSType_IndexedPageViewType();
$request->IndexedPageItemView->BasePoint = ‘Beginning’;
$request->IndexedPageItemView->Offset = 0;

$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;

$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;

Step 2: We will pass this request object into the $ews object.

Now you will get all inbox emails in associative array.We have got all inbox emails and attachments using Microsoft Exchange server API with PHP.