0

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

我们有一个非常频繁使用的组,经常会满员。目前我们必须使用 Outlook 手动删除,这需要一段时间。

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

有人有任何想法吗?

4

1 回答 1

0

您可以使用Item.DeleteEWS 的方法。

下面是从垃圾邮件文件夹中删除项目的示例。您应该将 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);
        }
    }
}

本文也可能对您有用:在 Exchange 中使用 EWS 删除项目

于 2018-07-11T08:45:49.307 回答