gpt4 book ai didi

java - 如何在 gwt 中获取电子邮件的内容?

转载 作者:行者123 更新时间:2023-11-29 09:17:55 25 4
gpt4 key购买 nike

我通过 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());
}

最佳答案

关于java - 如何在 gwt 中获取电子邮件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8353583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com