title: How to add attachments to email in Java using OutputStream?
body: <p>I've seen the code for <code>javax.mail</code> library where you add attachments to the email doing this:</p>
  
  <pre class="lang-java prettyprint-override"><code>MimeBodyPart attachmentPart = new MimeBodyPart();
  FileDataSource fds = new FileDataSource("C:/text.txt");
  attachmentPart.setDataHandler(new DataHandler(fds));
  attachmentPart.setFileName("text.txt");
  multipart.addBodyPart(attachmentPart);
  </code></pre>
  
  <p>But this requires that the file reside somewhere on this disk. </p>
  
  <p>I would like to grab an <code>OutputStream</code> right from the email library and stream file contents into it directly from another place where I write to that <code>OutputStream</code>.</p>
  
  <p>Is this possible?</p>