获取Outlook邮件的最新状态(回复或转发)

时间:2017-06-15 01:33:17

标签: vba outlook-vba

我正在开发Outlook VBA中的邮件自动化。我想使用 PR_VERB_EXECUTION_TIME 属性获取邮件的最新状态,并检查邮件是否已被回复或转发,如果邮件无人值守则发送邮件。

中的任何帮助



Sub Test(Item AS MailItem)
//Item is my incoming mail
Dim Obj As Outlook.MailItem
Dim str As String
Dim propaccessor As Outlook.Propertyaccessor
Set propaccessor = Item.propertyAccessor

str = propaccessor.Getproperty("http://schemas.microsoft.com/mapi/proptag/0x10820040")

**Str value is setting to null due to which error is thrown**
**but other properties are working fine**
**i want to use this string and compare current time and then reply if it is equal to current time**

End Sub




如何使用该属性表示赞赏!。

1 个答案:

答案 0 :(得分:2)

为此您需要使用PropertyAccessor.GetProperty方法

    For Each mailItem In mailitems
     If mailItem.Class <> olMail Then Exit For
     Set propertyAccessor = mailItem.propertyAccessor
     LastVerbExecuted = CheckBlankFields("PR_LAST_VERB_EXECUTED", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003"))
     Select Case LastVerbExecuted
       Case Last_Verb_Reply_All, Last_Verb_Reply_Sender, Last_Verb_Reply_Forward
          Subject = mailItem.Subject
          'This appears to be local time
          RecievedTime = mailItem.ReceivedTime
          'This appears to be GMT
          strRepliedTime = CheckBlankFields("PR_LAST_VERB_EXECUTION_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10820040"))
          OriginalAuthor = mailItem.Sender
          'Replier = ...
          If strRepliedTime <> "" Then
            'Convert string strRepliedTime to time format here...using a custom function
          End If
          LogData Subject, OriginalAuthor, Replier, RecievedTime, RepliedTime
       Case Else
         'in case you want to do something here
     End Select
   Next mailItem

参考http://www.tek-tips.com/viewthread.cfm?qid=1739523

你可以这样做

        Const Last_Verb_Reply_All = 103
    Const Last_Verb_Reply_Sender = 102
    Const Last_Verb_Reply_Forward = 104
    For Each mailItem In mailitems
     If mailItem.Class <> olMail Then Exit For
     Set propertyAccessor = mailItem.propertyAccessor
     LastVerbExecuted = CheckBlankFields("PR_LAST_VERB_EXECUTED", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003"))
     Select Case LastVerbExecuted
       Case Last_Verb_Reply_All, Last_Verb_Reply_Sender, Last_Verb_Reply_Forward
            'it means email already responded   
            exit sub
            'i dont think there is need to check time
          'strRepliedTime = CheckBlankFields("PR_LAST_VERB_EXECUTION_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10820040"))
       Case Else
         'in case you want to do something here
     End Select
    Next mailItem