当前位置: 技术问答>java相关
请教javamail收附件问题?
来源: 互联网 发布时间:2017-03-28
本文导语: 两天来欲哭无泪:各位大侠救命呀! 收邮件时不知怎样处理主体的每个部分,现在只能收到无附件和html格式的邮件,哪位好心人从理论和实际的角度给咱讲讲!谢谢。 源代码: =0;i--){ InternetAddress[] from = (Inter...
两天来欲哭无泪:各位大侠救命呀!
收邮件时不知怎样处理主体的每个部分,现在只能收到无附件和html格式的邮件,哪位好心人从理论和实际的角度给咱讲讲!谢谢。
源代码:
=0;i--){
InternetAddress[] from = (InternetAddress[])messages[i].getFrom();
InternetAddress[] to = (InternetAddress[])messages[i].getRecipients(Message.RecipientType.TO);
Part messagePart=messages[i];
Object content=messagePart.getContent();
if (content instanceof Multipart)
{
messagePart=((Multipart)content).getBodyPart(0);
String contentType=messagePart.getContentType();
System.out.println("CONTENT:"+contentType);
if (contentType.startsWith("text/plain")||contentType.startsWith("text/html"))
{
InputStream is = messagePart.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(is));
String thisLine=reader.readLine();
while (thisLine!=null)
{
System.out.println("thisLine:"+thisLine);
thisLine=reader.readLine();
}
}
}
else
out.println("
}
}catch(MessagingException e){
throw new Exception("Cannot read message.Please verify your E-mail server has a valid inbox");
}
finally {
store.close();
}
%>
收邮件时不知怎样处理主体的每个部分,现在只能收到无附件和html格式的邮件,哪位好心人从理论和实际的角度给咱讲讲!谢谢。
源代码:
=0;i--){
InternetAddress[] from = (InternetAddress[])messages[i].getFrom();
InternetAddress[] to = (InternetAddress[])messages[i].getRecipients(Message.RecipientType.TO);
Part messagePart=messages[i];
Object content=messagePart.getContent();
if (content instanceof Multipart)
{
messagePart=((Multipart)content).getBodyPart(0);
String contentType=messagePart.getContentType();
System.out.println("CONTENT:"+contentType);
if (contentType.startsWith("text/plain")||contentType.startsWith("text/html"))
{
InputStream is = messagePart.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(is));
String thisLine=reader.readLine();
while (thisLine!=null)
{
System.out.println("thisLine:"+thisLine);
thisLine=reader.readLine();
}
}
}
else
out.println("
邮件号:"+(i+1)+"
收件人:"+to[0].getAddress()+"
发件人:"+from[0].getAddress()+"
主 题:"+messages[i].getSubject()+"
时 间:"+messages[i].getSentDate()+"
内 容:"+messages[i].getContent()+"
");}
}catch(MessagingException e){
throw new Exception("Cannot read message.Please verify your E-mail server has a valid inbox");
}
finally {
store.close();
}
%>
|
顶上不是有吗?