I need to create an email with an attachment that is compiled on the fly. In my first draft of this, I built the attachment as a String. But on walkthru code, others noted that the string can be very large. Usually it is several thousand bytes, but sometimes it can be megabytes. Therefore, they said that I should write it in turn to a temporary file, and then attach the file to the letter. Otherwise, I may run out of empty space.
I am wondering if this really helps. If JavaMail reads the entire file into memory before sending, it does not matter. And, of course, creating a temporary file causes other troubles, such as finding the right directory to make sure I have permissions, etc. But if, instead, Javamail reads the file in some small chunks, then it would avoid the memory problem.
The bottom line is: as I understand it, Javamail sends synchronously. Therefore, if I create a file, send it, and then delete the file, there should be no problem deleting the file before actually sending it, right?
source
share