在Outlook中使用VBA来获取“已答复"或“转发"电子邮件对话的状态? [英] VBA in Outlook to get "replied" or "forwarded" status of email conversation?

查看:354
本文介绍了在Outlook中使用VBA来获取“已答复"或“转发"电子邮件对话的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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

解决方案

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

使用 OutlookSpy 查看消息-单击IMessage按钮以查看可用的MAPI属性. /p>

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.

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.

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@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

解决方案

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.

Take a look at a message with OutlookSpy - click IMessage button to see the available MAPI properties.

这篇关于在Outlook中使用VBA来获取“已答复"或“转发"电子邮件对话的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆