C# 4.0 使用带有C的Exchange server删除收件箱邮件项目
我已使用exchange Server 2007连接到邮件帐户。我能看懂邮件。在我阅读并解析邮件后,我需要从收件箱中删除邮件。请帮帮我。提前感谢我使用了以下代码:这将一起删除前10封邮件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("", "", "");
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);
}