使用带有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); }更多推荐
发布评论