08-02-2023, 04:04 PM
The situation is like this:
First, we generate a file in the memory, we can get a `InputStream` object.
Second the *InputStream* object must be send as a attachment of a email. The language is Java, we use Spring to send email.
I have found a lot of information, but I cannot find how to send an email attachment using `InputStream`. I try to do like this:
InputStreamSource iss= new InputStreamResource(new FileInputStream("c:\\a.txt"));
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.addAttachment("attachment", iss);
But I get an exception:
> Passed-in Resource contains an open stream: invalid argument. JavaMail
> requires an InputStreamSource that creates a fresh stream for every
> call.
First, we generate a file in the memory, we can get a `InputStream` object.
Second the *InputStream* object must be send as a attachment of a email. The language is Java, we use Spring to send email.
I have found a lot of information, but I cannot find how to send an email attachment using `InputStream`. I try to do like this:
InputStreamSource iss= new InputStreamResource(new FileInputStream("c:\\a.txt"));
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.addAttachment("attachment", iss);
But I get an exception:
> Passed-in Resource contains an open stream: invalid argument. JavaMail
> requires an InputStreamSource that creates a fresh stream for every
> call.