title: Disposing a MailMessage attachment
body: <p>Is it acceptable to do the following :</p>
  
  <pre><code>Attachment attachment = new Attachment(path, mediaType);
  
  //Do other stuff...
  
  using(attachment)
  {
     //Send email
  }
  </code></pre>
  
  <p>I usually create my disposable directly inside the using statement but in this case it's a bit complicated.</p>
  
  <p><strong>Background</strong></p>
  
  <p>I just encountered a bug in a legacy application where the email attachment is not releasing the file handle. So, the file can no longer be modified as it's already in use.</p>
  
  <p>It seems the problem is that the programmer forgot to call Dispose() on the attachment. Usually, this would be an easy problem to solve, but in this case, because of the structure of the code, I can't easily put the attachment inside a using directly when it's created.</p>
  
  <p>Is the alternative above a good compromise?</p>