Outlook中的VBA获取电子邮件会话的“回复”或“转发”状态?

时间:2013-03-10 08:49:10

标签: vba outlook imap

我在Outlook中有一个VBA脚本,旨在根据项目放在文件夹中的时间进行一些自动电子邮件处理。这可以按预期工作,但我正在尝试使其更加智能,以便脚本可以查看是否已回复放入文件夹的电子邮件。

目前,当邮件放在文件夹X中时,脚本会自动回复电子邮件,然后将邮件标记为未读。但是,如果邮件已被标记为“已回复”,则无论脚本是否回复邮件,或者有人在将邮件放入文件夹X之前发送了回复,我都要确保脚本不发送回复,并且只是将邮件标记为未读。这是通过阅读IMAP属性标签可以做到的吗?如果是的话,我在寻找哪个标签?我一直在努力弄清楚如何实现这一目标。任何帮助将不胜感激。

供参考,这是我的脚本(删除了识别细节):

注意:我知道我有一些声明的变量但没有被引用。我稍后会用这些东西。

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@email.com")
    msg.Send

End Sub

 '#################################################
Private Sub Application_Quit()

    Dim objNS As Outlook.NameSpace
    Set ackMsgs = Nothing
    Set fwdMsgs = Nothing
    Set objNS = Nothing

End Sub

1 个答案:

答案 0 :(得分:5)

您所追求的属性是PR_LAST_VERB_EXECUTED(DASL名称是http://schemas.microsoft.com/mapi/proptag/0x10810003);您应该可以使用MailItem.PropetyAccessor.GetProperty访问它。

查看带有OutlookSpy的邮件 - 单击“IMessage”按钮以查看可用的MAPI属性。