attachments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    attachments

    Code:
     [B]Multipart multipart = (Multipart) msg.getContent[/B]();   
        
        for (int j = 0; j < multipart.getCount(); j++) {   
         BodyPart bodyPart = multipart.getBodyPart(j);   
         InputStream stream = bodyPart.getInputStream();   
         BufferedReader br = new BufferedReader(new InputStreamReader(stream));   
     
         while (br.ready()) {   
          System.out.println(br.readLine());   
        }   
        }
        }
    i get org.apache.jasp er.JasperExcept ion: java.lang.Class CastException: java.lang.Strin g cannot be cast to javax.mail.Mult ipart
    root cause

    java.lang.Class CastException: java.lang.Strin g cannot be cast to javax.mail.Mult ipart
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Well, I guess the return value of msg.getContent( ) is a String. So no, you can't cast it to a Multipart object. Is there a specific reason you'd want to do this?

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      i want to get attachment

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        OK, step one would be to tell us where that attachment is. I'd guess it's in the msg object from what you've written but I don't know what type that object has.

        Also, you wanting the attachment doesn't explain (at least to me) why you're trying to get your hands on a Multipart object. Is it easier to get the attachment from a Multipart?

        Comment

        • oll3i
          Contributor
          • Mar 2007
          • 679

          #5
          I took it from a tutorial

          Comment

          • Nepomuk
            Recognized Expert Specialist
            • Aug 2007
            • 3111

            #6
            Well, we'll need more context nevertheless. Maybe link to the tutorial or post more code?

            Comment

            • oll3i
              Contributor
              • Mar 2007
              • 679

              #7

              Comment

              • Nepomuk
                Recognized Expert Specialist
                • Aug 2007
                • 3111

                #8
                OK, I've taken a quick look at the tutorial and it seems you're using a javax.mail.Mess age object. This implements the javax.mail.Part interface which has the getContent() function causing all of this trouble.

                This function returns an Object, so it could be anything. Apparently in this case it's a String. I'd recommend using [code=java]System.out.prin tln(msg.toStrin g());[/code] to have a closer look at what exactly it is.

                Comment

                Working...