Java mail problem transporting attachments from ImapBodyPart object

Discussion in 'Java' started by dalouis, Dec 8, 2006.

  1. dalouis

    dalouis Guest

    I have a question for anyone that can help. Im writing a very simple
    webmail application that works on imap and I have collected my
    attachments into MimeBodyPart Objects and now I have trouble sending
    them back to the web-user.

    The application runs on the server but the real client of the email is
    the webbrowser, as such I do not want to use the saveFile() method of
    MimeBodyPart. If I do use the saveFile() method , then it saves the
    file, correctly, to some file on my apache-jakarta machine.

    //this works fine but results in a file on the apache server which is
    no use to me.

    The attachment in my test case has a word document .doc file and i am
    trying to return it, via the apache machine, to the web client and have
    it open properly. So I tried using the methods
    getInputStream() and getRawInputStream() but when i
    do this I always end up with 0 bytes.

    Finally I tried the
    writeTo(java.io_OutputStream os)
    //Output the body part as an RFC 822 format stream.

    When I use this method it returns what seems to be the file but it
    seems to include headers in the stream which confuses microsoft word.
    Microsoft Word then displays the file like this:

    "Content-Type: application/msword; name="Mydoc.doc";
    x-mac-type="42494D41"; x-mac-creator="4D5357D4"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename="Mydoc.doc"


    Does anyone know how to properly send this attachment back to the
    webbrowser. It looks like i am missing something. Basically the code
    that i am using on the jsp engine is the following:

    response.setHeader("Content-disposition", "filename="+filename );
    OutputStream outputStream = response.getOutputStream();
    dalouis, Dec 8, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.