作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过 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());
}
最佳答案
你试过 MimeMessage.getContent() 了吗?
http://docs.oracle.com/javaee/1.4/api/javax/mail/internet/MimeMessage.html#getContent ()
关于java - 如何在 gwt 中获取电子邮件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8353583/
我是一名优秀的程序员,十分优秀!