2013-03-10 18 views
3

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

回答

4

你是後該物業是PR_LAST_VERB_EXECUTED(DASL名字是http://schemas.microsoft.com/mapi/proptag/0x10810003);你應該可以使用MailItem.PropetyAccessor.GetProperty訪問它。

查看OutlookSpy的消息 - 單擊IMessage按鈕以查看可用的MAPI屬性。

+0

真棒,我會給你一個鏡頭,讓你知道它是如何工作的!謝謝! :) – 2013-03-14 10:22:08

+0

也就是說,事實上,正是我所需要的。它甚至以我期望的方式運作。德米特里,非常感謝! – 2013-03-14 10:31:06

相關問題