I have a ZipInputStream. How can we send the ZipInputStream as an attachment (data.zip) via java mail?
I had seen some solution like using ByteArrayDatasource but since the MimeBodyPart receives InputStream as one constructor and we have an InputStream handy, I would like to know how to solve this issue without using ByteArrayDataSource.
I think you have made a wrong question, what you really want it is:
How can I attach a zip file into a email?
right? You cannot attach any object type you are waiting to attach a InputStream (ZipInputStream in this case) a InputStream is a Stream that allow to read bytes 1 by 1, or by a buffer.
You can use apache commons library commons-io to get a byte array and write those bytes in the filesystem
And I found here in the forums just to copy paste how you can attach the email: