防止在Outlook收件箱的一个特定子文件夹中删除电子邮件
本文关键字:一个 文件夹 电子邮件 删除 Outlook 收件箱 | 更新日期: 2023-09-27 18:18:06
我正试图找出如何限制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;
}
替换行
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"];