c#-4.0 - 使用 Exchange 服务器和 C# 删除收件箱邮件项目

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

我已使用 Exchange 服务器 (2007) 连接到邮件帐户。我能够阅读邮件。在我阅读并解析邮件项目后,我需要从收件箱中删除邮件项目。请帮我。提前致谢

最佳答案

我使用以下代码完成此操作:(这将一起删除前 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);
        }

关于c#-4.0 - 使用 Exchange 服务器和 C# 删除收件箱邮件项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26868350/

相关文章:

.net - PostSharp 1.5 和 .Net 4

c#-4.0 - Ninject.Extensions.Logging.Log4net 意外行为

multithreading - 如何在没有主线程等待的情况下从长时间运行的后台任务引发异常

c# - 已完成的 c# 任务再次运行...为什么?

c# - C# 中的数据网格访问

c# - ClickOnce 和不活动的主窗口

c# - 在C#中处理大文本文件

c#-4.0 - ASP.NET MVC 用户具有所有角色

multithreading - 我的System.Threading.Tasks.Task用法有什么问题?

c# - 来自另一个类的列表框计数项目始终返回 0