Store store = session.getStore("imaps");
  store.connect(host, "username",
     "password");//change the user and password accordingly
  Folder folder = store.getFolder("inbox");
  if (!folder.exists()) {
     System.out.println("inbox not found");
        System.exit(0);
  }
  folder.open(Folder.READ_ONLY);
  Date today=new Date();
  SearchTerm st = new ReceivedDateTerm(ComparisonTerm.EQ,today);
  Message[] messages = folder.search(st);
  for(int i=0;i<messages.length;i++)
  {
    String s1=messages[i].getSubject();
    if(s1!=null&&s1!="")
    {
    String s2="EXT: FSG daily shipment information";
    if(s1.equalsIgnoreCase(s2))
    {
  String contentType = messages[i].getContentType();
  String messageContent = "";
  // store attachment file name, separated by comma
  String attachFiles = "";
  if (contentType.contains("multipart")) {
      // content may contain attachments
      Multipart multiPart = (Multipart) messages[i].getContent();
      int numberOfParts = multiPart.getCount();
      for (int partCount = 0; partCount < numberOfParts; partCount++) {
          MimeBodyPart part = (MimeBodyPart)   multiPart.getBodyPart(partCount);
          if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
              // this part is attachment
              String fileName = part.getFileName();
              attachFiles += fileName + ", ";
              part.saveFile("C:/Users/rb842469/Documents/MailAttachments" + File.separator + fileName);
              HttpClient client = new HttpClient();
              PostMethod method = new PostMethod("https://dt-microservice-blobstore.run.aws-usw02-pr.ice.predix.io/uploadMultiBlob");
              method.addParameter("file",fileName);
              method.addParameter("directory","C:/Users/rb842469/Documents/MailAttachments");
              method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                                 new DefaultHttpMethodRetryHandler(3, false));
              client.getHostConfiguration().setProxy("ipaddress", port);
              int statusCode = client.executeMethod(method);
              byte[] responseBody = method.getResponseBody();
              //Print the response
             System.out.println(new String(responseBody));
          } 
      }
}
嗨,我正在研究 javax.mail 包以访问 webmail 或 Outlook 邮件。
- 在这里,我可以下载邮件中存在的附件,这些附件是根据搜索条件过滤的(我的搜索条件是将今天的邮件作为接收日期和代码中给出的主题)。 
- 但下载附件后,我尝试使用 HttpClient 和 PostMethod 将文件上传到 blobstore。在我给 PostMethod(url) 的代码中,这个 url 是我从 predix blobstore serviceinstance 获得的微服务 url。 
- 所以在运行代码后我得到 - {"timestamp":1476867898345,"status":500,"error":"Internal Server Error","exception":"org.springframework.web.multipart.MultipartException","message":"当前请求不是多部分请求","路径":"/uploadMultiBlob"} 
任何人都可以提出一些建议来解决这个问题吗?