0

I'm using simplejavamail to send emails with attachments. As an enhancement, I would like to load the file from the file path in a streaming fashion and add it as an attachment (just the stream). This way, I want to avoid loading entire file in memory.

Is there an API that does this already?

  • The web is a better place for a question like this than SO. Also, emailing gigabytes worth of files is not a good idea; the vast majority of email servers will reject such emails. – rzwitserloot Apr 11 '23 at 21:46
  • I did search for a long time and haven't found relevant answers - if not all, most of them point to the use case of streaming the input that loads everything in memory and then writes to a `Datasource` which is different than what I want to achieve. Also, I will be attaching a file that's about 15 MB in size but the memory issue comes into picture when multiple users trigger the endpoint at the same time to generate the attachment email. – underachiever Apr 11 '23 at 22:39
  • Spamming the mail server will probably just get you banned; it may be smarter to just use a lock to gate the sending so that only a few mails are sent simultaneously. – rzwitserloot Apr 11 '23 at 23:17
  • 15MB is just too big for an email really. You'd be better of using something else – g00se Apr 12 '23 at 00:01
  • The application/mail-server is currently able to handle the generation of several emails with attachments of size 15 MB. However, there is a notable spike in the memory usage which I'm concerned about. Thus came the thought of streaming the File to a Datasource instead of loading everything in memory. – underachiever Apr 12 '23 at 02:50

0 Answers0