1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Rep Power

    JavaMail / InputStream

    Hi guys,

    I've got the following code working almost perfectly apart from the InputStream seems to be losing the first line of the text file?

    Note: I have removed required try/catch blocks for readability.

    // Create a multipart message.
    // Assume the body text is already added
    Multipart oMultiPart = new MimeMultipart();
    String strLink = "http://mysite.com/file.txt";
    URL oURL = new URL(strLink);
    // oURL.openStream() returns the InputStream
    MimeBodyPart oAttachmentPart = new MimeBodyPart(oURL.openStream());
    The result is an email (it sends successfully) with a text file, called the correct thing (strLink), but it's missing the first line


    Text file is:
    First Line
    Second Line
    Third Line
    and the attachment is broken (no text shown).
    Whereas if I use this file, it is perfect
               (an intentionally blank line)
    First Line
    Second Line
    Third Line
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    London, ON
    Rep Power
    I don't see any obvious issues with your code, and I'm not sure what MimeBodyPart does/is, but I see in the constructor doc Available Here it notes that
    The input stream must start at the beginning of a valid MIME body part and must terminate at the end of that body part.
    Note that the "boundary" string that delimits body parts must not be included in the input stream. The intention is that the MimeMultipart parser will extract each body part's bytes from a multipart stream and feed them into this constructor, without the delimiter strings.
    Are you sure that you have satisfied these conditions?
    <Tetrad> the program I just wrote 1) compiled the first time without any errors and 2) worked like it was supposed to
    <Tetrad> I don't know whether to be proud or scared to death
    Originally Posted by DaWei_M
    That covers a multitude of your sins, right there.

IMN logo majestic logo threadwatch logo seochat tools logo