title: Close outlook application
body: <p>It is very possible that this question has been asked (many times) before but i can't find a solution.</p>
  
  <p>I have a program that will send an email. 
  The code looks something like this:</p>
  
  <pre><code>Dim oApp As Interop.Outlook.Application = Nothing
  While oApp Is Nothing
      Try
          oApp = New Interop.Outlook.Application
      Catch ex As Exception
          oApp = Nothing
          Dim result As Integer = MessageBox.Show("Outlook is already running, close Outlook and click OK to continue sending this email or click Cancel to skip sending this email.", "Outlook", MessageBoxButtons.OKCancel)
          If result = DialogResult.Cancel Then
              Exit Sub
          End If
      End Try
  End While
  </code></pre>
  
  <p>So far so good. The user is forced to close outlook to use the outlook application. When this is done, i do this:</p>
  
  <pre><code>Dim eMail As Interop.Outlook._MailItem
  eMail = oApp.CreateItem(Interop.Outlook.OlItemType.olMailItem)
  
  'To who?
  eMail.To = "person@domain.com"
  
  'Sbuject
  eMail.Subject = "Foo"
  
  'Message
  Dim message As String = "Bar"
  eMail.HTMLBody = message
  
  'Send
  eMail.Send()
  </code></pre>
  
  <p>Works like a charm, but when this is done i have this little icon in the tray telling med that outlook is running, and if i try to open my outlook client i get a message that outlook is allready running. I have to click the icon in the tray to close before i can use the client. How do i close this application from my code when the mail is sent?</p>
  
  <p>I have tried this with no sucess:</p>
  
  <pre><code>oApp.Quit()
  oApp.Application.Quit()
  System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp)
  oApp = Nothing
  </code></pre>
  
  <p>Any help is appreciated. </p>