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/