Outlook 中的 VBA 获取电子邮件对话的“已回复”或“已转发”状态?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15320510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA in Outlook to get "replied" or "forwarded" status of email conversation?
提问by Charles Neitzel
I have a VBA script in outlook that is designed to do some automatic email handling based on when items are placed in folders. That works as intended, but I'm trying to make it a little more intelligent so the script can see whether or not the email being placed into the folder has been replied to.
我在 Outlook 中有一个 VBA 脚本,旨在根据项目放置在文件夹中的时间进行一些自动电子邮件处理。这按预期工作,但我试图让它更智能一点,以便脚本可以查看放入文件夹的电子邮件是否已被回复。
Currently, the moment a mail is placed in folder X, the script sends an automatic reply to the email and then marks the mail as unread. However if a mail has already been flagged as "replied", regardless of if the script replied to the mail or if someone sent a reply before placing the mail into folder X, I want to make sure the script does NOT send a reply, and simply marks the mail as unread. Is this something that's possible to do by reading IMAP property tags? If so, which tag am I looking for? I've been struggling to figure out how to accomplish this. Any help would be appreciated.
目前,当邮件被放入文件夹 X 时,脚本会自动回复该电子邮件,然后将邮件标记为未读。但是,如果邮件已被标记为“已回复”,无论脚本是否回复了邮件,或者是否有人在将邮件放入文件夹 X 之前发送了回复,我都想确保脚本不会发送回复,并且简单地将邮件标记为未读。这是可以通过读取 IMAP 属性标签来实现的吗?如果是这样,我要寻找哪个标签?我一直在努力弄清楚如何实现这一点。任何帮助,将不胜感激。
For reference, here's the script I have (with identifying details removed):
作为参考,这是我的脚本(删除了识别细节):
Note: I am aware I have some declared variables but not referenced. I'm going to use these later for something else.
注意:我知道我有一些声明的变量但没有被引用。稍后我会将这些用于其他用途。
Option Explicit
'##############################################
'### all code for the ThisOutlookSession module
'### Module level Declarations
'expose the items in the target folder to events
Dim WithEvents ackSpamMsgs As Items
Dim WithEvents ackPhishMsgs As Items
Dim WithEvents fwdMsgs As Items
'###############################################
Private Sub Application_Startup()
'some startup code to set our "event-sensitive"
'items collection
Dim objNS As Outlook.NameSpace
Dim ackFolder As Folder
Dim compFolder As Folder
Set objNS = Application.GetNamespace("MAPI")
Set ackMsgs = objNS.Folders("Inbox").Folders("Folder X").Items
Set fwdMsgs = objNS.Folders("Inbox").Folders("Folder Y").Items
End Sub
'#################################################
'### this is the ItemAdd event code
Sub ackMsgs_ItemAdd(ByVal Item As Object)
'when a new item is added to our "watched folder"
'we can process it
Dim msg As MailItem
Set msg = Item.Reply
'This is where I want to check if the mail has been replied to, and skip the "with"
'below if it has been replied to.
With msg
.Subject = "RE: " & Item.Subject
.HTMLBody = "Body of email here"
.Send
Set msg.UnRead = True
End With
End Sub
Sub fwdMsgs_ItemAdd(ByVal Item As Object)
Dim msg As MailItem
Dim newMsg As MailItem
Set msg = Item.Forward
msg.Recipients.Add ("[email protected]")
msg.Send
End Sub
'#################################################
Private Sub Application_Quit()
Dim objNS As Outlook.NameSpace
Set ackMsgs = Nothing
Set fwdMsgs = Nothing
Set objNS = Nothing
End Sub
回答by Dmitry Streblechenko
The property you are after is PR_LAST_VERB_EXECUTED (DASL name is http://schemas.microsoft.com/mapi/proptag/0x10810003
); you should be able to access it using MailItem.PropetyAccessor.GetProperty
.
您所追求的属性是 PR_LAST_VERB_EXECUTED(DASL 名称是http://schemas.microsoft.com/mapi/proptag/0x10810003
);您应该可以使用MailItem.PropetyAccessor.GetProperty
.
Take a look at a message with OutlookSpy- click IMessage button to see the available MAPI properties.
使用OutlookSpy查看消息- 单击 IMessage 按钮以查看可用的 MAPI 属性。