在方法体中可以将 content 打印出来, 但是不能将 conteng 返回,
很诡异的问题啊...虚心求教!public static String getMailContent(Part part)throws Exception{
StringBuffer bodytext = new StringBuffer();
String contenttype = part.getContentType();
int nameindex = contenttype.indexOf("name");
boolean conname =false;
if(nameindex != -1) conname=true;
//System.out.println("CONTENTTYPE: "+contenttype);
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("multipart/*")){
Multipart multipart = (Multipart)part.getContent();
int counts = multipart.getCount();
for(int i=0;i<counts;i++){
getMailContent(multipart.getBodyPart(i));
}
}else if(part.isMimeType("message/rfc822")){
getMailContent((Part)part.getContent());
}
String content = bodytext.toString();
System.out.println(content);
return content;
}
在其他方法中调用该方法,取到的值为空...String content = getMailContent((Part)msg);
System.out.println("内容:" + content);代码没有BUG 可以正常运行控制台输出:第2封邮件
发件人:[email protected]
主题:webmail测试
发送日期:2009-05-11 07:12:23
大小:78KB邮件测试 怎么总是不行?!内容:
很诡异的问题啊...虚心求教!public static String getMailContent(Part part)throws Exception{
StringBuffer bodytext = new StringBuffer();
String contenttype = part.getContentType();
int nameindex = contenttype.indexOf("name");
boolean conname =false;
if(nameindex != -1) conname=true;
//System.out.println("CONTENTTYPE: "+contenttype);
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("multipart/*")){
Multipart multipart = (Multipart)part.getContent();
int counts = multipart.getCount();
for(int i=0;i<counts;i++){
getMailContent(multipart.getBodyPart(i));
}
}else if(part.isMimeType("message/rfc822")){
getMailContent((Part)part.getContent());
}
String content = bodytext.toString();
System.out.println(content);
return content;
}
在其他方法中调用该方法,取到的值为空...String content = getMailContent((Part)msg);
System.out.println("内容:" + content);代码没有BUG 可以正常运行控制台输出:第2封邮件
发件人:[email protected]
主题:webmail测试
发送日期:2009-05-11 07:12:23
大小:78KB邮件测试 怎么总是不行?!内容:
解决方案 »
- (2783631 ms) [http-8089-4] WARN : org.apache.struts.action.RequestProcessor#proc
- 大家给个解决方法,我要怎么才能看这样的文件
- 请教大家一个正则表达式
- 有关求无限分级目录下的产品信息的SQL
- 表达试语言能否引用JSF定义的受控bean,如果能,能否发个例字看看!
- 高分求助!!!如何把页面表单输出到Excel打印,注意要原格式
- 如何在我的网页中加入其他网页的某一个元素
- 求助:一个绝对路径和相对路径的问题
- 哪位给推荐几篇关于权限分配的理论文章?(明天上午结贴)
- Servlet如何向位于另一台机器的Servlet发送含有Multipart的Post请求,急!!!
- 求个JAVA struts+dao设计的登陆
- jsp wml 服务器端接受到的是乱码 帮忙解决哈
百思不得其解....求救!
发件人:[email protected]
主题:图片邮件
发送日期:2009-05-11 09:53:25
大小:46KB
CONTENTTYPE: multipart/mixed;
boundary="----=_Part_0_17028773.1242021172390"
CONTENTTYPE: multipart/related;
boundary="----=_Part_1_17713075.1242021172437"
CONTENTTYPE: text/html;charset=GB2312
带图片的邮件!<img src="cid:qq">
CONTENTTYPE: application/octet-stream内容:------------------------多了一行 CONTENTTYPE: application/octet-stream
是什么意思?
将StringBuffer定义在方法体外边就可以了
private StringBuffer bodytext = new StringBuffer();
public String getBodyText(){
return bodytext.toString();
}
怎么会外边访问不到?楼主,加把劲,再研究一下,是这个原因吗?