Announcement Announcement Module
No announcement yet.
Mail attachment Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mail attachment


    I already have the binary content for my attachment - it is a PDF file and it is held in the byte array listed below (called content). But when I try to send the mail using JavaMailSenderImpl I get the exception listed at the bottom.

    My problem is, I dont see another interface method call that is appropriate for me ... I really dont want to save the byte[] to disk, just so I can passin a instance...

    Has anyone else come across this?

    byte[] content = someByteArrayWithContent;

    ByteArrayInputStream inputStream = new ByteArrayInputStream(content),

    InputStreamResource isr = new InputStreamResource(inputStream);

    helper.addAttachment(attachmentName, isr);

    21-03-05 12:17:12:777 - {DEBUG} actions.IncidentAction Thread [http-8080-Processor5]; returning bean with name [mailEngine]
    21-03-05 12:17:13:309 - {ERROR} actions.IncidentAction Thread [http-8080-Processor5]; An error occurred [InputStream has already been read - do not use InputStreamResource if a stream needs to be read multiple times]
    java.lang.IllegalStateException: InputStream has already been read - do not use InputStreamResource if a stream needs to be read multiple times
    at tInputStream(
    at org.springframework.mail.javamail.MimeMessageHelpe r$1.getInputStream(
    at javax.activation.DataHandler.writeTo(DataHandler.j ava:287)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyP
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyP
    at javax.mail.internet.MimeMultipart.writeTo(MimeMult
    at com.sun.mail.handlers.multipart_mixed.writeTo(mult
    at javax.activation.ObjectDataContentHandler.writeTo(
    at javax.activation.DataHandler.writeTo(DataHandler.j ava:295)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyP
    at javax.mail.internet.MimeMessage.writeTo(MimeMessag
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTr
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(
    at com.acompany.tracker.utils.MailEngine.sendMessage(
    at com.acompany.tracker.incidents.actions.IncidentAct ion.sendMVIRViaEmail(
    at com.acompany.tracker.incidents.actions.IncidentAct ion.saveNewIncident(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at org.apache.struts.actions.DispatchAction.dispatchM ethod(
    at com.acompany.tracker.common.CommonAction.execute(C
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(
    at org.apache.struts.action.RequestProcessor.process(
    at org.apache.struts.action.ActionServlet.process(Act
    at org.apache.struts.action.ActionServlet.doPost(Acti
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:809)

  • #2
    There was quite a long email thread on this subject recently which may help:

    Go to,
    and select '2' at the top right, and look for
    10 Mar 15:34 Henry Lu Send email with attachment


    • #3
      This link will not depend of the amount of topics :