怎样用javamail收取含附件的邮件,熟悉javamail的请近
当一个邮件MIMEtype是“multipart/*”时,会得到Part对象,用下面的方法处理。为什么第18行得不到正文的内容呢?第24行处理正确,能正常显示附件名称。是代码有问题还是处理的方法不对。或者还有其他原因,请高手多多指正。
1 public String getPart(Part part, int partNum)
2 throws MessagingException,IOException
3 {
4 String s="";
5 String s1="";
6 String s2="";
7 String s3="";
8 String sct = part.getContentType();
9 if (sct == null)
10 {
11 s="part 无效";
12 return s;
13 }
14 ContentType ct = new ContentType(sct);
15 if (ct.match("text/plain"))
16 {
17 // display text/plain inline
18 s1="<pre>"+(String)part.getContent()+"</pre>";
19 }
20 else
21 {
22 String temp="";
23 if ((temp = part.getFileName()) != null)
24 s2= "<b>Filename:</b> " + temp + "<br>";
25 temp = null;
26 if ((temp = part.getDescription()) != null)
27 s3= "<b>Description:</b> " + temp + "<br>";
28 }
29 s=s1+s2+s3;
30 return s;
31 }