当前位置: 首页>>代码示例>>C#>>正文


C# ExchangeService.BindToItems方法代码示例

本文整理汇总了C#中ExchangeService.BindToItems方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.BindToItems方法的具体用法?C# ExchangeService.BindToItems怎么用?C# ExchangeService.BindToItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExchangeService的用法示例。


在下文中一共展示了ExchangeService.BindToItems方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckMail

        public void CheckMail()
        {
            try
            {
                string processLoc = dataActionsObject.getProcessingFolderLocation();
                StreamWriter st = new StreamWriter("C:\\Test\\_testings.txt");
                string emailId = "[email protected]";// ConfigurationManager.AppSettings["UserName"].ToString();
                if (emailId != string.Empty)
                {
                    st.WriteLine(DateTime.Now + " " + emailId);
                    st.Close();
                    ExchangeService service = new ExchangeService();
                    service.Credentials = new WebCredentials(emailId, "Sea2013");
                    service.UseDefaultCredentials = false;
                    service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
                    Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
                    SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
                    if (inbox.UnreadCount > 0)
                    {
                        ItemView view = new ItemView(inbox.UnreadCount);
                        FindItemsResults<Item> findResults = inbox.FindItems(sf, view);
                        PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients);
                        itempropertyset.RequestedBodyType = BodyType.Text;
                        //inbox.UnreadCount
                        ServiceResponseCollection<GetItemResponse> items = service.BindToItems(findResults.Select(item => item.Id), itempropertyset);
                        MailItem[] msit = getMailItem(items, service);

                        foreach (MailItem item in msit)
                        {
                            item.message.IsRead = true;
                            item.message.Update(ConflictResolutionMode.AlwaysOverwrite);
                            foreach (Attachment attachment in item.attachment)
                            {
                                if (attachment is FileAttachment)
                                {
                                    string extName = attachment.Name.Substring(attachment.Name.LastIndexOf('.'));
                                    FileAttachment fileAttachment = attachment as FileAttachment;
                                    FileStream theStream = new FileStream(processLoc + fileAttachment.Name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                                    fileAttachment.Load(theStream);
                                    byte[] fileContents;
                                    MemoryStream memStream = new MemoryStream();
                                    theStream.CopyTo(memStream);
                                    fileContents = memStream.GetBuffer();
                                    theStream.Close();
                                    theStream.Dispose();
                                    Console.WriteLine("Attachment name: " + fileAttachment.Name + fileAttachment.Content + fileAttachment.ContentType + fileAttachment.Size);
                                }
                            }
                        }
                    }
                    DeleteMail(emailId);
                }
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:virtuoso-pra,项目名称:ReadEmail,代码行数:58,代码来源:CheckEmail.cs

示例2: DumpMIME

        /// <summary>
        /// Get the MimeContent of each Item specified in itemIds and write it
        /// to the destination folder.
        /// </summary>
        /// <param name="itemIds">ItemIds to retrieve</param>
        /// <param name="destinationFolderPath">Folder to save messages to</param>
        /// <param name="service">ExchangeService to use to make EWS calls</param>
        public static void DumpMIME(
            List<ItemId> itemIds,
            string destinationFolderPath,
            ExchangeService service)
        {
            DebugLog.WriteVerbose(String.Format("Getting {0} items by ItemId.", itemIds.Count));

            PropertySet mimeSet = new PropertySet(BasePropertySet.IdOnly);

            mimeSet.Add(EmailMessageSchema.MimeContent);
            mimeSet.Add(EmailMessageSchema.Subject);

            //mimeSet.Add(AppointmentSchema.MimeContent);
            //mimeSet.Add(AppointmentSchema.Subject);
            //mimeSet.Add(AppointmentSchema.RequiredAttendees);
            //mimeSet.Add(AppointmentSchema.OptionalAttendees);
            ServiceResponseCollection<GetItemResponse> responses = service.BindToItems(itemIds, mimeSet);

            DebugLog.WriteVerbose("Finished getting items.");

            foreach (GetItemResponse response in responses)
            {
                switch (response.Result)
                {
                    case ServiceResult.Success:
                        DumpMIME(response.Item, destinationFolderPath);
                        break;
                    case ServiceResult.Error:
                        DumpErrorResponseXML(response, destinationFolderPath);
                        break;
                    case ServiceResult.Warning:
                        throw new NotImplementedException("DumpMIME doesn't handle ServiceResult.Warning.");
                    default:
                        throw new NotImplementedException("DumpMIME encountered an unexpected ServiceResult.");
                }
            }

            DebugLog.WriteVerbose("Finished dumping MimeContents for each item.");
        }
开发者ID:haiyangIt,项目名称:Haiyang,代码行数:46,代码来源:DumpHelper.cs

示例3: BatchGetEmailItems

        public static Collection<EmailMessage> BatchGetEmailItems(ExchangeService service, Collection<ItemId> itemIds)
        {

            // Create a property set that limits the properties returned by the Bind method to only those that are required.
            PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.ToRecipients);

            // Get the items from the server.
            // This method call results in a GetItem call to EWS.
            ServiceResponseCollection<GetItemResponse> response = service.BindToItems(itemIds, propSet);

            // Instantiate a collection of EmailMessage objects to populate from the values that are returned by the Exchange server.
            Collection<EmailMessage> messageItems = new Collection<EmailMessage>();


            foreach (GetItemResponse getItemResponse in response)
            {
                try
                {
                    Item item = getItemResponse.Item;
                    EmailMessage message = (EmailMessage)item;
                    messageItems.Add(message);
                    // Print out confirmation and the last eight characters of the item ID.
                    System.Console.WriteLine("Found item {0}.", message.Id.ToString().Substring(144));
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Exception while getting a message: {0}", ex.Message);
                }
            }

            // Check for success of the BindToItems method call.
            if (response.OverallResult == ServiceResult.Success)
            {
                System.Console.WriteLine("All email messages retrieved successfully.");
                System.Console.WriteLine("\r\n");
            }

            return messageItems;
        }
开发者ID:fernandoklst,项目名称:Development,代码行数:39,代码来源:Program.cs

示例4: GetAtendees

        private static IEnumerable<Attendee> GetAtendees(ExchangeService service, ServiceId serviceId)
        {
            var result = service.BindToItems(new[] {new ItemId(serviceId.UniqueId)},
                                             new PropertySet(BasePropertySet.FirstClassProperties)).SingleOrDefault();

            var appointment = (Appointment) result.Item;

            // TODO re factor attendee creation to remove code duplication
            return appointment.RequiredAttendees.Select(a => new Attendee {
                Name = a.Name,
                ResponseType = a.ResponseType.ToString()
            });
        }
开发者ID:boiledfrogs,项目名称:TimeIsMoney,代码行数:13,代码来源:MeetingController.cs

示例5: DumpXML

        /// <summary>
        /// Dump the properties from the given PropertySet of every item in the 
        /// ItemId list to XML files.
        /// </summary>
        /// <param name="itemIds">List of ItemIds to get</param>
        /// <param name="propertySet">PropertySet to use when getting items</param>
        /// <param name="destinationFolderPath">Folder to save messages to</param>
        /// <param name="service">ExchangeService to use to make EWS calls</param>
        public static void DumpXML(
            List<ItemId> itemIds,
            PropertySet propertySet,
            string destinationFolderPath,
            ExchangeService service)
        {
            DebugLog.WriteVerbose(String.Format("Getting {0} items by ItemId.", itemIds.Count));
            ServiceResponseCollection<GetItemResponse> responses = service.BindToItems(itemIds, propertySet);
            DebugLog.WriteVerbose("Finished getting items.");

            DebugLog.WriteVerbose("Started writing XML dumps to files.");
            foreach (GetItemResponse response in responses)
            {
                switch (response.Result)
                {
                    case ServiceResult.Success:
                        DumpXML(response.Item, destinationFolderPath);
                        break;
                    case ServiceResult.Error:
                        DumpErrorResponseXML(response, destinationFolderPath);
                        break;
                    case ServiceResult.Warning:
                        throw new NotImplementedException("DumpXML doesn't handle ServiceResult.Warning.");
                    default:
                        throw new NotImplementedException("Unexpected ServiceResult.");
                }
            }

            DebugLog.WriteVerbose("Finished writing XML dumps to files.");
        }
开发者ID:haiyangIt,项目名称:Haiyang,代码行数:38,代码来源:DumpHelper.cs

示例6: DumpMIMEToString

        /// <summary>
        /// Get the MimeContent of each Item specified in itemIds and write it
        /// to a string.
        /// </summary>
        /// <param name="itemIds">ItemIds to retrieve</param>
        /// <param name="destinationFolderPath">Folder to save messages to</param>
        /// <param name="service">ExchangeService to use to make EWS calls</param>
        /// <param name="TheMime">MIME string to set</param>
        public static void DumpMIMEToString(
            List<ItemId> itemIds,
            ExchangeService service,
            ref string TheMime)
        {
            DebugLog.WriteVerbose(String.Format("Getting {0} items by ItemId.", itemIds.Count));
            string MimeToReturn = string.Empty;
            PropertySet mimeSet = new PropertySet(BasePropertySet.IdOnly);

            mimeSet.Add(EmailMessageSchema.MimeContent);
            mimeSet.Add(EmailMessageSchema.Subject);

            ServiceResponseCollection<GetItemResponse> responses = service.BindToItems(itemIds, mimeSet);

            DebugLog.WriteVerbose("Finished getting items.");

            foreach (GetItemResponse response in responses)
            {
                switch (response.Result)
                {
                    case ServiceResult.Success:
                        if (response.Item.MimeContent == null)
                        {
                            throw new ApplicationException("No MIME content to write");
                        }
                        UTF8Encoding oUTF8Encoding = new UTF8Encoding();
                        MimeToReturn = oUTF8Encoding.GetString(response.Item.MimeContent.Content);

                        break;
                    case ServiceResult.Error:
                        MimeToReturn =
                                "ErrorCode:           " + response.ErrorCode.ToString() + "\r\n" +
                                "\r\nErrorMessage:    " + response.ErrorMessage + "\r\n";

                        break;
                    case ServiceResult.Warning:
                        throw new NotImplementedException("DumpMIMEToString doesn't handle ServiceResult.Warning.");
                    default:
                        throw new NotImplementedException("DumpMIMEToString encountered an unexpected ServiceResult.");
                }
            }

            TheMime = MimeToReturn;

            DebugLog.WriteVerbose("Finished dumping MimeContents for each item.");
        }
开发者ID:haiyangIt,项目名称:Haiyang,代码行数:54,代码来源:DumpHelper.cs


注:本文中的ExchangeService.BindToItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。