title: Stream as an Attachment to System.Net.Mail is 0 bytes
body: <p>I've got a project where I'm using a PDF generator to send a file to a user.  We'd like to give the user the option to attach this file to an email instead, and we're having trouble using the Stream object and Attachment logic together.</p>
  
  <p>We start with ABCpdf, which has two save methods: it can save to a Stream, or if you give it a string, it'll try to save to a file on the disk there.  We've done both no problem.</p>
  
  <pre><code>Stream stream = new MemoryStream();
  myPdf.Save(stream);
  </code></pre>
  
  <p>Everything is mostly cool at this point - <code>stream</code> has several kilobytes of data, and if you .Save() to a file, you get an actual file with the same number of bytes.</p>
  
  <p>So we attach to an email at this point (after initializing the mail object, setting To: and From:, etc.):</p>
  
  <pre><code>mail.Attachments.Add(new Attachment(stream, "myPdf.pdf"));
  mail.Send();
  </code></pre>
  
  <p>...which gets us as far as receiving an email with 0 bytes, but the proper filename.  </p>
  
  <p>All the examples I'm finding online use a StreamReader or a StreamWriter or a Flush() or something.  It always seems like it's more complicated than simply passing a Stream, but maybe only one or two lines more complicated.  None of those examples start with a Stream - they're always trying to turn an array into a Stream to show you how easy that is, or grab a file from disk (which we can't do, which is why we're excited to use a Stream).</p>
  
  <p>Anyway, if anyone can explain what I'm doing wrong or what I ought to be doing, I'd really appreciate it.  Thanks.</p>