我在服务器上通过gwt rpc运行以下代码:
public class MailHandlerServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
MimeMessage message = new MimeMessage(session, req.getInputStream());
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我不知道解析MimeMessage
的函数。如何获取MimeMessage
的内容?
这里是我编写的简单代码,但它不起作用:
Object content = message.getContent();
if(content instanceof Multipart){
Multipart mp = (Multipart)content;
int count3 = mp.getCount();
for(int i = 0;i < count3;i++){
BodyPart p = mp.getBodyPart(i);
if(p.isMimeType("text/plain")){
TextBody data = (TextBody) p.getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
data.writeTo(baos);
String datafull = new String(baos.toByteArray());
PrintWriter out = resp.getWriter();
out.print(datafull.toString());
}
答案 0 :(得分:0)
您是否尝试过MimeMessage.getContent()?
http://docs.oracle.com/javaee/1.4/api/javax/mail/internet/MimeMessage.html#getContent()