日期:2014-05-20  浏览次数:20754 次

javamail 如何正确显示复合邮件
当收到的邮件存在二种类型plain,html时,如何正确显示呢,其实读出来这二种类型的内容是一样的.求助更完善的代码.谢谢.

public   void   getMContent(Part   part)throws   MessagingException{  

        String   contenttype=part.getContentType();  
      bodytext.append( "type= "+(String)part.getContentType()+ " <br> ");  
        int   nameindex=contenttype.indexOf( "name ");  
boolean   conname=false;  
        if(nameindex!=-1)   conname=true;  
        try{  
        if(part.isMimeType( "multipart/* ")){  
          Multipart   multipart=(Multipart)part.getContent();  
            int   counts=multipart.getCount();  
            for(int   i=0;i <counts;i++){  
            getMContent(multipart.getBodyPart);  
        }  
        }  
        else{  

        if(part.isMimeType( "text/plain ")&&!conname){  
      bodytext.append((String)part.getContent());  
        }else  
if(part.isMimeType( "text/html ")&&!conname){  
      bodytext.append((String)part.getContent());  
        }else  
          if(part.isMimeType( "message/rfc822 ")){  
          getMContent((Part)part.getContent());  
      }  

        }  
        }catch(Exception   exp){}  
}  


------解决方案--------------------
顶了!
------解决方案--------------------
http://topic.csdn.net/t/20050722/13/4161400.html
你看看,希望对你
------解决方案--------------------
两种类型?

一般邮件正文可能会和添附文件的类型不一样
不知道lz所说的
当收到的邮件存在二种类型
这个2种类型是什么意思呢?
------解决方案--------------------
你要注意你的编码方式。
------解决方案--------------------
ding