我想将删除邮件发送到用户创建的文件夹而不是已删除的项目文件夹。
有没有办法拦截我从邮件中删除或从文件夹/收件箱中删除的邮件并将其发送到该用户定义的文件夹?
我以为我可以编写一个脚本来查看已删除邮件文件夹中的邮件,然后将其移至用户定义的文件夹,但是我实际上将永远无法正确删除任何内容,因为它会不断将其移回。而如果我可以在单击删除按钮后拦截它,如果我真的想删除它,我总是可以选择将消息“移动”到已删除的项目文件夹中。
我想将删除邮件发送到用户创建的文件夹而不是已删除的项目文件夹。
有没有办法拦截我从邮件中删除或从文件夹/收件箱中删除的邮件并将其发送到该用户定义的文件夹?
我以为我可以编写一个脚本来查看已删除邮件文件夹中的邮件,然后将其移至用户定义的文件夹,但是我实际上将永远无法正确删除任何内容,因为它会不断将其移回。而如果我可以在单击删除按钮后拦截它,如果我真的想删除它,我总是可以选择将消息“移动”到已删除的项目文件夹中。
我想我会看到 VBA 会是什么样子。它不漂亮,但它有效。
Private WithEvents olDeletedItems As items
Private WithEvents olToBeDeletedItems As items
Private Sub Application_Startup ()
Dim objNS As NameSpace
Dim Cancel As Boolean
Set objNS = Application.GetNamespace("MAPI")
Set olDeletedItems = objNS.GetDefaultFolder(olFolderDeletedItems).items
Debug.Print "Adding items to the - Deleted Items - folder will trigger olDeletedItems_ItemAdd"
Set olToBeDeletedItems = objNS.GetDefaultFolder(olFolderInbox).Folders("To be deleted").items
Debug.Print "Adding items to the - To be deleted - folder will trigger olToBeDeletedItems_ItemAdd"
End Sub
Private Sub olDeletedItems_ItemAdd(ByVal item As Object)
Dim myNameSpace As NameSpace
Dim targetFolder As MAPIFolder
On Error GoTo notYes ' There is an error when there is nothing in SoftDelete
Debug.Print item.Subject & " - " & item.UserProperties("SoftDelete").Value
If item.UserProperties("SoftDelete").Value <> "Yes" Then
GoTo notYes
Else
'The item has already been soft deleted
' Okay to remain in the real deleted folder
End If
On Error GoTo 0
Exit Sub
notYes:
Debug.Print item.Subject & " - Either not a Yes or there is nothing in SoftDelete"
Set myNameSpace = Application.GetNamespace("MAPI")
Set targetFolder = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("@To be deleted")
item.Move targetFolder
Set myNameSpace = Nothing
Set targetFolder = Nothing
End Sub
Private Sub olToBeDeletedItems_ItemAdd(ByVal item As Object)
item.UserProperties.Add("SoftDelete", olText).Value = "Yes"
item.Save
End Sub
UserProperty
您可以在您的Item
(邮件、任务、日历等)上分配一个自定义,以便一旦将其放置在用户定义的DeletedItems
文件夹中,它就可以被永久删除。
然后将其移动到用户定义的逻辑DeletedItems
可以检查用户属性是否存在......
if (mailItem.UserProperties["SoftDelete"] != null)
// keep in REAL deleted items
else
{
// move to user-defined deleted items
mailItem.UserProperties.Add("SoftDelete", Outlook.OlUserPropertyType.olYesNo, false, false).Value = true;
mailItem.Save(); // persist user props
}