Exchange WebSerivce Usage

//ExchangeService版本为2007SP1              

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);            

//参数是用户名,密码,域              

service.Credentials = new WebCredentials("[email protected]", "xxxxxx", "xxx");            

//给出Exchange Server的URL              

//service.Url = new Uri("mail.xxxx.com");            

//你自己的邮件地址 [email protected]              

service.AutodiscoverUrl("[email protected]");            

//创建过滤器, 条件为邮件未读.              

SearchFilter sf = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);            

//查找Inbox,加入过滤器条件,结果10条              

FindItemsResults<Item> findResults = service.FindItems(                 WellKnownFolderName.Inbox,                 sf,                 new ItemView(100));

            if (findResults.Items.Count > 0)          

   {             

    PropertySet detailedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.Recurrence);

                service.LoadPropertiesForItems(from Item item in findResults select item, detailedPropertySet);      

       }

            foreach (Item item in findResults.Items)      

       {            

     EmailMessage email = EmailMessage.Bind(service, item.Id);

                string content = item.Body.Text;

                if (!email.IsRead)              

   {                     Console.WriteLine(email.Body);             

        //标记为已读                  

     email.IsRead = true;                  

   //将对邮件的改动提交到服务器                

       email.Update(ConflictResolutionMode.AlwaysOverwrite);    

       }      

       }

你可能感兴趣的:(webserivce)