当 deleted/moved 到垃圾箱时将项目标记为已读
Mark items as read when deleted/moved to trash
在 Outlook 2010 中,使用下面的代码,我删除或移入垃圾文件夹的任何内容都会自动标记为已读。
Option Explicit
Dim WithEvents DeletedItems As Outlook.Items
Private Sub Application_Startup()
Set DeletedItems = Session.GetDefaultFolder(olFolderDeletedItems).Items
End Sub
Private Sub DeletedItems_ItemAdd(ByVal Item As Object)
If Item.UnRead = True Then
Item.UnRead = False
Item.Save
End If
End Sub
它在 Outlook 2013 中根本不起作用。
这是我用来检查 Outlook 如何查看已删除电子邮件的 read/unread 状态的代码。我从 .
中提取了 Pause
函数
Private Sub DeletedItems_ItemAdd(ByVal Item As Object)
RememberItem Item 'Remember which email this is
Debug.Print "At start: " & Item.UnRead 'Should be True
If Item.UnRead = True Then
Item.UnRead = False
Item.Save
End If
Debug.Print "After mark read: " & Item.UnRead 'Should be False
Pause 10 'In separate module. Code from
Debug.Print "After pause: " & Item.UnRead 'Should be False unless item has become Unread
End Sub
Private Function RememberItem(Optional ByVal Item As Object) As Object
'Allows check-up on the deleted item after event-handler is done with it.
Static oDeleted As Object
If Not Item Is Nothing Then Set oDeleted = Item
Set RememberItem = oDeleted
End Function
Private Sub CheckStatus()
Dim CheckItem As Object
Set CheckItem = RememberItem
Debug.Print "Follow-up check: " & CheckItem.UnRead 'Should be False
End Sub
我得到的输出:
- 开始时:正确(项目未读 - 这是正确的)
- 标记阅读后:错误(项目已阅读 - 这可能正确也可能不正确)
- 暂停后:错误(已读取项目 - 这是不正确的)
- 后续检查:错误(已读取项目 - 这是不正确的)
更新:
标记为有效的答案确实解决了我的问题,尽管我偶尔仍会看到一些奇怪的行为。
多一点挖掘发现根本原因是 Outlook 和电子邮件服务器之间的同步问题。 Outlook 会删除内容,但同步会很麻烦,看起来 Outlook 在将自己的更新发回之前从服务器中提取更新。这些差异似乎导致 Outlook 无法跟踪已删除电子邮件应处于的状态。
我的工作场所使用 Google 应用程序作为他们的电子邮件提供商,我已经使用正确的 IMAP 设置在 Outlook 中设置了所有内容,但是 Google 和 Outlook 运行不佳。能够通过使用所选答案和 Google 的 Outlook syncing tool for Google Apps.
消除所有不可预测的行为
还确认我的原始代码在与 Google 应用程序同步工具结合使用时表现正常。
我应该早点意识到问题可能是 Google 和 Outlook 一起出现问题,但我什至没有想到,这就是为什么我没有提到 Google 这个等式的组成部分。
这对于评论来说太长了,但我对这个问题感到困惑,所以我会用我自己的话重述一下,以阐明并逐步展示这个过程。
The item gets deleted and may or may not have been read.
The DeletedItems_ItemAdd
procedure is automatically called.
- It seems like you may be having issues with this being called sometimes, but that this is not your main issue.
Item.UnRead
is output. This seems to be working.
The message is checked to see whether it is unread, using the Item.UnRead
property. This will return False
if read, and True
if not read. Item.UnRead
is then set to False
if it was True
. If it was already False
, it remains False
. At this point, EVERY message should have the Item.UnRead
property equal to False
which actually indicates that the item has been read.
Item.UnRead
is output.
- What I am interpreting from your question is that this is always
False
, which means the item is read. Per step 4, I believe this SHOULD be False
.
- Your note suggests that this "may or may not be correct," but I do not understand when it is not correct.
There is a pause.
Item.UnRead
is output.
- Your note suggests that this has a value of
False
, indicating the item has been read. You believe this to be incorrect. I do not understand why.
A follow-up check is performed, outside of the normal procedure. I will assume that the code works correctly and that the correct message is checked. Again, you note that Item.UnRead
is False
, indicating the message has been read and then state that this is incorrect. Again, I do not understand why this is incorrect.
如果我的分析有误,请指正,以便我提供帮助。照原样,我无法理解这个问题。该代码似乎试图通过将 Item.UnRead
属性 设置为 False
来设置要读取的每条消息。我能看到的每张支票都在返回 False
。预期的行为是什么?
我无法弄清楚您遇到的确切问题,因为我无法复制它,但试试这个:
Option Explicit
Dim WithEvents MainFolder As Outlook.Folder
Private Sub Application_Startup()
Set MainFolder = Session.GetDefaultFolder(olFolderInbox)
End Sub
Private Sub MainFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, Cancel As Boolean)
If MoveTo.Name = Session.GetDefaultFolder(olFolderDeletedItems).Name And Item.UnRead = True Then
Item.UnRead = False
Item.Save
End If
End Sub
在 Outlook 2010 中,使用下面的代码,我删除或移入垃圾文件夹的任何内容都会自动标记为已读。
Option Explicit
Dim WithEvents DeletedItems As Outlook.Items
Private Sub Application_Startup()
Set DeletedItems = Session.GetDefaultFolder(olFolderDeletedItems).Items
End Sub
Private Sub DeletedItems_ItemAdd(ByVal Item As Object)
If Item.UnRead = True Then
Item.UnRead = False
Item.Save
End If
End Sub
它在 Outlook 2013 中根本不起作用。
这是我用来检查 Outlook 如何查看已删除电子邮件的 read/unread 状态的代码。我从
Pause
函数
Private Sub DeletedItems_ItemAdd(ByVal Item As Object)
RememberItem Item 'Remember which email this is
Debug.Print "At start: " & Item.UnRead 'Should be True
If Item.UnRead = True Then
Item.UnRead = False
Item.Save
End If
Debug.Print "After mark read: " & Item.UnRead 'Should be False
Pause 10 'In separate module. Code from
Debug.Print "After pause: " & Item.UnRead 'Should be False unless item has become Unread
End Sub
Private Function RememberItem(Optional ByVal Item As Object) As Object
'Allows check-up on the deleted item after event-handler is done with it.
Static oDeleted As Object
If Not Item Is Nothing Then Set oDeleted = Item
Set RememberItem = oDeleted
End Function
Private Sub CheckStatus()
Dim CheckItem As Object
Set CheckItem = RememberItem
Debug.Print "Follow-up check: " & CheckItem.UnRead 'Should be False
End Sub
我得到的输出:
- 开始时:正确(项目未读 - 这是正确的)
- 标记阅读后:错误(项目已阅读 - 这可能正确也可能不正确)
- 暂停后:错误(已读取项目 - 这是不正确的)
- 后续检查:错误(已读取项目 - 这是不正确的)
更新:
标记为有效的答案确实解决了我的问题,尽管我偶尔仍会看到一些奇怪的行为。
多一点挖掘发现根本原因是 Outlook 和电子邮件服务器之间的同步问题。 Outlook 会删除内容,但同步会很麻烦,看起来 Outlook 在将自己的更新发回之前从服务器中提取更新。这些差异似乎导致 Outlook 无法跟踪已删除电子邮件应处于的状态。
我的工作场所使用 Google 应用程序作为他们的电子邮件提供商,我已经使用正确的 IMAP 设置在 Outlook 中设置了所有内容,但是 Google 和 Outlook 运行不佳。能够通过使用所选答案和 Google 的 Outlook syncing tool for Google Apps.
消除所有不可预测的行为还确认我的原始代码在与 Google 应用程序同步工具结合使用时表现正常。
我应该早点意识到问题可能是 Google 和 Outlook 一起出现问题,但我什至没有想到,这就是为什么我没有提到 Google 这个等式的组成部分。
这对于评论来说太长了,但我对这个问题感到困惑,所以我会用我自己的话重述一下,以阐明并逐步展示这个过程。
The item gets deleted and may or may not have been read.
The
DeletedItems_ItemAdd
procedure is automatically called.
- It seems like you may be having issues with this being called sometimes, but that this is not your main issue.
Item.UnRead
is output. This seems to be working.The message is checked to see whether it is unread, using the
Item.UnRead
property. This will returnFalse
if read, andTrue
if not read.Item.UnRead
is then set toFalse
if it wasTrue
. If it was alreadyFalse
, it remainsFalse
. At this point, EVERY message should have theItem.UnRead
property equal toFalse
which actually indicates that the item has been read.
Item.UnRead
is output.
- What I am interpreting from your question is that this is always
False
, which means the item is read. Per step 4, I believe this SHOULD beFalse
.- Your note suggests that this "may or may not be correct," but I do not understand when it is not correct.
There is a pause.
Item.UnRead
is output.
- Your note suggests that this has a value of
False
, indicating the item has been read. You believe this to be incorrect. I do not understand why.A follow-up check is performed, outside of the normal procedure. I will assume that the code works correctly and that the correct message is checked. Again, you note that
Item.UnRead
isFalse
, indicating the message has been read and then state that this is incorrect. Again, I do not understand why this is incorrect.
如果我的分析有误,请指正,以便我提供帮助。照原样,我无法理解这个问题。该代码似乎试图通过将 Item.UnRead
属性 设置为 False
来设置要读取的每条消息。我能看到的每张支票都在返回 False
。预期的行为是什么?
我无法弄清楚您遇到的确切问题,因为我无法复制它,但试试这个:
Option Explicit
Dim WithEvents MainFolder As Outlook.Folder
Private Sub Application_Startup()
Set MainFolder = Session.GetDefaultFolder(olFolderInbox)
End Sub
Private Sub MainFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, Cancel As Boolean)
If MoveTo.Name = Session.GetDefaultFolder(olFolderDeletedItems).Name And Item.UnRead = True Then
Item.UnRead = False
Item.Save
End If
End Sub