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

  • Mail attachment

    Hi,

    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 java.io.File 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 org.springframework.core.io.InputStreamResource.ge tInputStream(InputStreamResource.java:75)
    at org.springframework.mail.javamail.MimeMessageHelpe r$1.getInputStream(MimeMessageHelper.java:735)
    at javax.activation.DataHandler.writeTo(DataHandler.j ava:287)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyP art.java:1147)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyP art.java:668)
    at javax.mail.internet.MimeMultipart.writeTo(MimeMult ipart.java:233)
    at com.sun.mail.handlers.multipart_mixed.writeTo(mult ipart_mixed.java:67)
    at javax.activation.ObjectDataContentHandler.writeTo( DataHandler.java:839)
    at javax.activation.DataHandler.writeTo(DataHandler.j ava:295)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyP art.java:1147)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessag e.java:1607)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTr ansport.java:390)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:245)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:232)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:228)
    at com.acompany.tracker.utils.MailEngine.sendMessage( MailEngine.java:57)
    at com.acompany.tracker.incidents.actions.IncidentAct ion.sendMVIRViaEmail(IncidentAction.java:322)
    at com.acompany.tracker.incidents.actions.IncidentAct ion.saveNewIncident(IncidentAction.java:287)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.struts.actions.DispatchAction.dispatchM ethod(DispatchAction.java:276)
    at com.acompany.tracker.common.CommonAction.execute(C ommonAction.java:142)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
    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 http://news.gmane.org/gmane.comp.jav...framework.user,
    and select '2' at the top right, and look for
    10 Mar 15:34 Henry Lu Send email with attachment

    Comment


    • #3
      This link will not depend of the amount of topics :
      http://thread.gmane.org/gmane.comp.j...work.user/5454

      Steph

      Comment

      Working...
      X