使用带有C#的Exchange服务器删除收件箱邮件项(Delete inbox mail item using Exchange server with C#)

编程入门 行业动态 更新时间:2024-10-28 19:28:09
使用带有C#的Exchange服务器删除收件箱邮件项(Delete inbox mail item using Exchange server with C#) 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)连接到邮件帐户。 我能够阅读邮件项目。 在我读取并解析邮件项目后,我需要从收件箱中删除邮件项目。 请帮帮我。 提前致谢

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

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

最满意答案

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

I did it using following code: (This will delete the first 10 mails together)

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

更多推荐

本文发布于:2023-08-02 06:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1370968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收件箱   邮件   服务器   Exchange   Delete

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!