从Office 365组删除电子邮件

时间:2018-07-10 19:39:55

标签: office365 exchangewebservices

有人知道是否可以将EW与C#或Powershell或其他任何选项一起使用,以从Office 365组中删除电子邮件。

我们有一个使用率很高的团队,经常忙得不可开交。目前,我们必须使用需要一定时间的Outlook手动删除。

尝试了Office 365保留删除策略,但它似乎不想删除电子邮件。

有人知道吗?

1 个答案:

答案 0 :(得分:0)

您可以使用EWS的Item.Delete方法。

下面是从垃圾邮件文件夹中删除项目的示例。您应该更改 将WellKnownFolderName属性设置为要从中删除项目的任何文件夹。 您可能还希望将pageSize属性增加到更适合您的需求。

private void JunkEmailCleanup()
{
    // Connect to the Exchange web service.
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
    service.Credentials = new WebCredentials(Account_UserName, Account_Password, Account_Domain);
    service.Url = new Uri(Service_URL);

    // Set the page size.
    const int pageSize = 20;
    // Set the ItemView with the page size.
    ItemView view = new ItemView(pageSize);
    // Indicate that the base property will be the item identifier.
    view.PropertySet = new PropertySet(BasePropertySet.IdOnly);

    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.JunkEmail, view);

    if (findResults != null)
    {
        foreach (EmailMessage item in findResults)
        {
            item.Delete(DeleteMode.HardDelete, true);
        }
    }
}

本文可能对您也有用:Deleting items by using EWS in Exchange

相关问题