'This method can't be used with an inline response mail item

I have an Outlook add-in that monitors sent items and moves specific emails to a folder. I am not sure what have changed, but when I send an email, I get this error:

This method can't be used with an inline response mail item.

enter image description here

enter image description here

Here is my code. It fails while moving the mail item (Mail.Move(TargetFolder)) when IsSentItem is true:

Private Sub MoveMailToFolder(ByVal TargetFolder As Outlook.Folder, ByVal Mail As Outlook.MailItem, ByVal IsSentItem As Boolean)
        Try
            If Mail.ReadReceiptRequested Then
                ''continue /keep original mail as is
            Else
                'Mail.UnRead = False
                Mail.UnRead = True
            End If

            If IsSentItem Then
                Mail.UnRead = False
                Mail.Move(TargetFolder)
            Else
                Mail.Move(TargetFolder)
                'Mail.SaveSentMessageFolder = TargetFolder
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString & " " & ex.HResult.ToString & " " & ex.GetBaseException.ToString)
        Finally
            ''
        End Try
    End Sub

Can you advise how this can be fixed?



Solution 1:[1]

Yes, the inline response needs to be closed first. You also need to avoid calling methods like that from inline response or MailItem event handlers. In the latter case, you can start a timer (use the Timer class from the Forms namespace rather than Threading as it fires on the main thread) and call code like yours in the timer event handler (when you are out of the MailItem event handler).

To close an inline response, you can try to use Accessibility API to simulate a click on the "Discard" button or, if using Redemption (I am its author) is an option, its SafeExplorer object - it exposes ActiveInlineResponseDiscard method:

set sExplorer = CreateObject("Redemption.SafeExplorer")
sExplorer.Item = Application.ActiveExplorer
sExplorer.ActiveInlineResponseDiscard

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1