String userName = "your userName ";
String passWord = "your passWord ";
String domain = "domain Name ";
String url = "https: // exchange server address/EWS/Exchange. asmx ";
ExchangeServiceBinding exchangeServer = new ExchangeServiceBinding ();
ICredentials creds = new NetworkCredential (userName, passWord, domain );
// Establish a trusted connection
ExchangeServer. Credentials = creds;
ExchangeServer. Url = url;
// Define the inbox of the email
DistinguishedFolderIdType [] folderIDArray = new DistinguishedFolderIdType [1];
FolderIDArray [0] = new DistinguishedFolderIdType ();
FolderIDArray [0]. Id = DistinguishedFolderIdNameType. inbox;
PathToUnindexedFieldType ptuftDisplayName = new PathToUnindexedFieldType ();
PtuftDisplayName. FieldURI = UnindexedFieldURIType. folderDisplayName;
PathToExtendedFieldType pteftComment = new PathToExtendedFieldType ();
PteftComment. PropertyTag = "0x3004"; // PR_COMMENT
PteftComment. PropertyType = mapipropertypetype. String;
// Define the GetFolderType object and set the corresponding attributes
GetFolderType myfoldertype = new GetFolderType ();
Myfoldertype. FolderIds = folderIDArray;
Myfoldertype. FolderShape = new FolderResponseShapeType ();
Myfoldertype. FolderShape. BaseShape = DefaultShapeNamesType. IdOnly;
Myfoldertype. FolderShape. AdditionalProperties = new BasePathToElementType [2];
Myfoldertype. FolderShape. AdditionalProperties [0] = ptuftDisplayName;
Myfoldertype. FolderShape. AdditionalProperties [1] = pteftComment;
// Obtain the folder set on the server
GetFolderResponseType myFolder = exchangeServer. GetFolder (myfoldertype );
// Get the inbox
FolderInfoResponseMessageType firmtInbox = (FolderInfoResponseMessageType) myFolder. ResponseMessages. Items [0];
// Display the inbox
// Console. WriteLine (string. Format ("got folder: {0}", firmtInbox. Folders [0]. DisplayName ));
PathToUnindexedFieldType ptuftSubject = new PathToUnindexedFieldType ();
PtuftSubject. FieldURI = UnindexedFieldURIType. itemSubject;
PathToUnindexedFieldType ptuftBody = new PathToUnindexedFieldType ();
PtuftBody. FieldURI = UnindexedFieldURIType. itemAttachments;
PathToExtendedFieldType pteftFlagStatus = new PathToExtendedFieldType ();
PteftFlagStatus. PropertyTag = "0x1090"; // PR_FLAG_STATUS
PteftFlagStatus. PropertyType = MapiPropertyTypeType. Integer;
// Define the FindItemType object to obtain the set in the inbox
FindItemType findItemRequest = new FindItemType ();
FindItemRequest. Traversal = ItemQueryTraversalType. Shallow;
FindItemRequest. ItemShape = new ItemResponseShapeType ();
FindItemRequest. ItemShape. BaseShape = DefaultShapeNamesType. AllProperties;
FindItemRequest. ParentFolderIds = new FolderIdType [1];
FindItemRequest. ParentFolderIds [0] = firmtInbox. Folders [0]. FolderId;
// Obtain the email
FindItemResponseType firt = exchangeServer. FindItem (findItemRequest );
// Cyclically iterate each email
Foreach (FindItemResponseMessageType firmtMessage in firt. ResponseMessages. Items)
{
// If the email is included, it is displayed
If (firmtMessage. RootFolder. TotalItemsInView> 0)
{
// Cyclically iterate the details of each email
Foreach (ItemType it in (ArrayOfRealItemsType) firmtMessage. RootFolder. Item). Items)
{
If (MessageType) (it). IsRead = false)
{
& Nbs