【问题标题】:Prevent emails from being deleted in one specific child folder of the Outlook inbox防止电子邮件在 Outlook 收件箱的特定子文件夹中被删除
【发布时间】:2016-01-14 16:12:10
【问题描述】:

我试图弄清楚如何限制 Outlook 2010 中的一个文件夹删除它的邮件项。我有以下代码示例运行良好,但仅适用于收件箱文件夹(OlDefaultFolders.olFolderInbox)。我试图弄清楚如何限制一个文件夹和一个仅在收件箱下方的文件夹。例如 Inbox\ReadMail 我想阻止用户仅从 ReadMail 中删除。提前感谢您的任何帮助。

 public partial class ThisAddIn
{
    Microsoft.Office.Interop.Outlook.MailItem mail = null;
    Outlook.Inspectors inspectors = null;
    Outlook.Folder fldr = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        inspectors = this.Application.Inspectors;

        // Is there a way to edit the folloing line to point to a certain sub folder of the inbox folder?
        inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler (Inspectors_NewInspector);

        fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

        fldr.BeforeItemMove += new Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(fldr_BeforeItemMove);

    }

    void fldr_BeforeItemMove(object Item, Microsoft.Office.Interop.Outlook.MAPIFolder MoveTo, ref bool Cancel)
    {
        MessageBox.Show("You are not permitted to delete emails from this folder");
        Cancel = true;
    }

【问题讨论】:

    标签: c# visual-studio outlook-addin outlook-2010 outlook-redemption


    【解决方案1】:

    换行

    fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
    

    fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Folders["ReadMail"];
    

    【讨论】:

    • 我错过了 .Folders ...我也问了错误的问题。我需要防止从存储级别向下删除,而不是在收件箱文件夹级别向下删除,所以我最终得到了这个 - fldr = (Outlook.Folder)this.Application.Session.DefaultStore.GetRootFolder().Folders["ReadMail"] ;但是你让我走上了正确的道路,可以这么说:)
    • 如果您在 Outlook 2003 或更早版本中运行,存储不会公开,但您仍然可以通过打开收件箱文件夹的父级使您的代码工作:Application.Session.GetDefaultFolder(olFolderInbox).Parent .Folders["ReadMail"];
    • 最后一个问题。有没有办法处理 ReadMail 的子文件夹?我也在尝试限制子文件夹。我不确定是否可以使用某种通配符。我想如果没有通配符来包含子文件夹,我需要构建一组文件夹,但我什至尝试修改原始行以仅包含一个子文件夹作为 test 。示例 fldr = (Outlook.Folder)this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Folders["ReadMail\1"];包括一个子文件夹“1”,但我无法确定语法
    • 是的,您需要将文件夹引用存储在一个列表中,并在每个文件夹上分别设置一个事件处理程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    相关资源
    最近更新 更多