Delete inbox mail item using Exchange server with C#

sum*_*man 2 c#-4.0

     public static ReadMail()
     {
        ExchangeService Service = new ExchangeService();
        Service.Credentials = new WebCredentials("", "", "");
        Service.AutodiscoverUrl("xyz@xyz.com");
        Folder inbox = Folder.Bind(Service, WellKnownFolderName.Inbox);
        StreamingSubscription streamingsubscription = Service.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);
        var connection = new StreamingSubscriptionConnection(Service, 30);
        connection.AddSubscription(streamingsubscription);
        connection.OnNotificationEvent += OnNotificationEvent;
        connection.Open();
    }

    private static void OnNotificationEvent(object sender, NotificationEventArgs args)
    {
        Item mail = args.Subscription.Service.FindItems(WellKnownFolderName.Inbox, new ItemView(10)).Items[0];
    }
Run Code Online (Sandbox Code Playgroud)

I'm connected to a mail account using exchange server(2007). I'm able to read the mail item. after i read & parse the mail item i need to delete the mail item from the inbox. Please help me. Thanks in advance

小智 6

我使用以下代码完成了此操作:(这将一起删除前10个邮件)

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
        service.Credentials = new WebCredentials("xxx@yyy.com", "******");
        service.AutodiscoverUrl("xxx@yyy.com");
        FindItemsResults<Item> items = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        if (items.Count() != 0)
        {
            IEnumerable<ItemId> itemIds = from p in items.Items select p.Id;
            service.DeleteItems(itemIds, DeleteMode.MoveToDeletedItems, null, null);
        }
Run Code Online (Sandbox Code Playgroud)