我想將刪除郵件發送到用戶創建的文件夾而不是刪除的郵件文件夾。Outlook 2007 - 攔截郵件刪除命令
有沒有辦法截取我從郵件中刪除或從文件夾/收件箱中刪除並將郵件發送到該用戶定義文件夾的郵件?
我以爲我可以編寫一個腳本來觀察郵件的已刪除郵件文件夾,然後將其移動到用戶定義的文件夾,但我永遠不會真的能夠正確刪除任何東西,因爲它會繼續移動它。而如果我可以在點擊刪除按鈕後攔截它,我總是可以選擇將郵件「移動」到刪除的項目文件夾中,如果我真的想刪除它的話。
我想將刪除郵件發送到用戶創建的文件夾而不是刪除的郵件文件夾。Outlook 2007 - 攔截郵件刪除命令
有沒有辦法截取我從郵件中刪除或從文件夾/收件箱中刪除並將郵件發送到該用戶定義文件夾的郵件?
我以爲我可以編寫一個腳本來觀察郵件的已刪除郵件文件夾,然後將其移動到用戶定義的文件夾,但我永遠不會真的能夠正確刪除任何東西,因爲它會繼續移動它。而如果我可以在點擊刪除按鈕後攔截它,我總是可以選擇將郵件「移動」到刪除的項目文件夾中,如果我真的想刪除它的話。
,這樣一旦它被放置在用戶定義的文件夾DeletedItems
它可能被永久刪除您可以在您的Item
(郵件,任務,日曆等)指定自定義UserProperty
。
的是移動它做的邏輯,然後用戶定義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
}
我以爲我會看到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