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));
}
}
}
Hi, I am doing work on javax.mail package to access the webmail or outlook mails.
Here I'm able to download the attachments present in the mails which are filtered based on search condition(My search condition is having mails with today as received date and subject given in code).
But after downloading the attachments i tried to upload files to blobstore using HttpClient and PostMethod. In code i gave PostMethod(url),this url is my microservice url got from predix blobstore serviceinstance.
So after running the code i'm getting
{"timestamp":1476867898345,"status":500,"error":"Internal Server Error","exception":"org.springframework.web.multipart.MultipartException","message":"The current request is not a multipart request","path":"/uploadMultiBlob"}
Can anyone give some suggestions to solve this issue?