Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 使用带有C的Exchange server删除收件箱邮件项目_C# 4.0 - Fatal编程技术网

C# 4.0 使用带有C的Exchange server删除收件箱邮件项目

C# 4.0 使用带有C的Exchange server删除收件箱邮件项目,c#-4.0,C# 4.0,我已使用exchange Server 2007连接到邮件帐户。我能看懂邮件。在我阅读并解析邮件后,我需要从收件箱中删除邮件。请帮帮我。提前感谢我使用了以下代码:这将一起删除前10封邮件 public static ReadMail() { ExchangeService Service = new ExchangeService(); Service.Credentials = new WebCredentials("", "", "");

我已使用exchange Server 2007连接到邮件帐户。我能看懂邮件。在我阅读并解析邮件后,我需要从收件箱中删除邮件。请帮帮我。提前感谢

我使用了以下代码:这将一起删除前10封邮件

     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];
    }

谢谢你,阿利克斯·董。很抱歉迟了答复。我解决了这个问题。你的代码也有帮助。
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);
        }