javamail Part to get MimeBodyPart

netizen1
netizen1 used Ask the Experts™
on
In my code:
Part part;
System.out.println( "Class: " + p.getClass().toString() );

if(( p.getClass().toString().compareTo("class javax.mail.internet.MimeBodyPart") == 0) && 
             ( p.getContentType().equals( "image/gif" )))
          {
{
a.  MimeBodyPart mbp = (MimeBodyPart)p.getClass();
  System.out.println( "cid: " + mbp.getContentId() );
}

a.  Gives me an error of "java.lang.ClassCastException"
Is there a valid way of doing this?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Java Developer
Top Expert 2010
Commented:
if(( p instanceof MimeBodyPart) && 
            ( p.getContentType().equals( "image/gif" )))
         {
{
  MimeBodyPart mbp = (MimeBodyPart)p;
 System.out.println( "cid: " + mbp.getContentId() );
}

Author

Commented:
Thanks allot.  Sometimes it takes others input to see the obvious.

Thanks again
Mick BarryJava Developer
Top Expert 2010

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial