title: VSTO Outlook Visual Basic - Handle Mail Item Closure
body: <p>I'm creating an Outlook Add-In, and am struggling to detect and handle the event when a mail item is closed. The inspectors_NewInspector function is triggered sucessfully (as I can obtain the subject and sender of the email), but I cannot get the mailItem_close() function to be called at all.</p>
  <pre><code>        
  Public Class ThisAddIn
      Public WithEvents inspectors As Outlook.Inspectors
      Public WithEvents mailItem As Outlook.MailItem
  
      Private Sub ThisAddIn_Startup() Handles Me.Startup
          inspectors = Me.Application.Inspectors
      End Sub
  
      Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
  
      End Sub
      Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
          If Inspector.CurrentItem.size &gt; 0 And Inspector.CurrentItem.class = 43 Then
              mailItem = Inspector.CurrentItem
              Dim mSubject As String = mailItem.Subject
              Dim mFrom As String = mailItem.SenderEmailAddress
              Dim mTime As String = mailItem.ReceivedTime
              'MsgBox(mSubject)
          End If
      End Sub
  
      Private Sub mailItem_Close()
          MsgBox(&quot;closing&quot;)
      End Sub
  </code></pre>