Amrita Deb
Amrita Deb

Reputation: 335

How to reference the original mail of a reply?

I have code which when I reply to a mail asks which folder the reply should be saved to.

I need to extend it to move the mail I replied to (the parent mail) to also save in the folder I chose for the reply mail.

I feel this can be done if I could make an object of the Parent mail with maybe Conversation ID?

Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim myFolder As MAPIFolder
    Dim myOlApp As Outlook.Application
    Dim myOlExp As Outlook.Explorer

    If Environ("MailSave") = True Then
        If TypeName(Item) = "MailItem" Then
            Set myOlApp = CreateObject("Outlook.Application")
            Set olNS = myOlApp.GetNamespace("MAPI")
            Set myFolder = olNS.PickFolder
            
            'todo
            If Not (myFolder Is Nothing) Then
                Set Item.SaveSentMessageFolder = myFolder
                'Item.Parent.Move myFolder ---I tried this. But it is wrong I know
                ' MsgBox ("All moved")
            
            End If
        End If
    End If
End Sub

Upvotes: 0

Views: 522

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49397

You may look at the "In-Reply-To" header (exposed by the PR_IN_REPLY_TO_ID MAPI property), but these values are written after the ItemSend event is fired.

I'd suggest handling the MailItem.Reply event which is fired when the user selects the Reply action for an item, or when the Reply method is called for the item. Also you may be interested in the MailItem.Forward event which is fired when the user selects the Forward action for an item, or when the Forward method is called for the item.

Public WithEvents myItem As MailItem  

Sub Initialize_Handler()  
  Set myItem = Application.ActiveInspector.CurrentItem  
End Sub 

Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean)  
  Set Response.SaveSentMessageFolder = myItem.Parent  
End Sub

So, following that way you will be able to access the original item and set the SaveSentMessageFolder property.

Upvotes: 1

Related Questions