Results 1 to 3 of 3

Thread: Mail attachment

Hybrid View

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    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
    Chris Harris
    Carlisle, UK

  3. #3

    Default

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

    Steph

Similar Threads

  1. Spring-based Mail Template Framework
    By eisenb in forum Architecture
    Replies: 3
    Last Post: Dec 2nd, 2010, 07:24 AM
  2. How to set attachment 's encoding
    By kongqz in forum Data
    Replies: 3
    Last Post: Jun 30th, 2006, 01:38 AM
  3. Get a exception when I send mail
    By kongqz in forum Web
    Replies: 2
    Last Post: Aug 21st, 2005, 06:28 PM
  4. How to run the program. Sending Mail
    By kotesh in forum Web
    Replies: 0
    Last Post: May 13th, 2005, 02:38 AM
  5. mail and authentication
    By lixin_chu in forum Container
    Replies: 0
    Last Post: Mar 15th, 2005, 08:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •