title: Automate Sending an email through Microsoft Outlook
body: <p>I am new to C# and I am attempting to automate sending an email from Outlook through the following code and it works fine in the development environment. I would like it to use the default user as the sender even if outlook is not open.</p>
  
  <pre><code>        private void EmailMessage(string recipient, string subject, string body)
      {
          Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
          Microsoft.Office.Interop.Outlook.MailItem email = (Outlook.MailItem)application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
  
          try
          {
              email.Subject = subject;
              email.Body = body;
              email.To = recipient;
              ((Outlook._MailItem)email).Send();
              _emailConfirmation = true;
          }
  
          catch (System.Runtime.InteropServices.COMException ex)
          {
              Logging.LogError("Trip Email Failed", ExceptionHelper.GetInnerMostException(ex));
              _emailConfirmation = false;
          }
  
          finally
          {
              //release the objects used to send email after message has been sent\\
              if (email != null)
                  System.Runtime.InteropServices.Marshal.ReleaseComObject(email);
              if (application != null)
                  System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
          }
      }
  </code></pre>
  
  <p>All users are assigned an account and have Outlook installed with a valid anti-virus. My concern is when it goes live, it will fail on the creation of a new instance of outlook or something else I am just not seeing. Do you think this will work with what I intend to accomplish when it goes live?</p>
  
  <p>There is no error in the code, however I am seeing a lot of posts from people saying that you should not create an instance of outlook.application directly.</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/office/bb622502.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/office/bb622502.aspx</a></p>
  
  <p>I think I may just be paranoid because I've never used a PIA before</p>