以下是我们使用的Java代码:
String contentType = message.getContentType();
String attachFiles = "";
// String saveDirectory = (String) resources.get(SystemRqstAppConstants.WebConstants.CUSTOMERITEMVENDORPO_PATH);
String saveDirectory ="D:/ResumeFiles/";
List<String> errorsList= null;
String messageContent = "";
logger.info(":::::Timecards Auto Update before Attchments:::::");
if (contentType.contains("multipart")) {
// content may contain attachments
String client="";
if(subject.contains("xxxx") || subject.contains("xxxx") || subject.contains("xxxx"))
client="xxxx";
else if(subject.contains("xxx") || subject.contains("xxx") || subject.contains("xxx"))
client="xxx";
logger.info("Timecards Auto Update client name: "+client);
Multipart multiPart = (Multipart) message.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
fileName = part.getFileName();
attachFiles += fileName + ", ";
saveDirectory = saveDirectory+client+"/";
File folder = new File(saveDirectory);
if(!folder.exists())
folder.mkdir();
String destFilePath = saveDirectory+fileName;
logger.info("Timecards Auto Update destFilePath: "+destFilePath);
FileOutputStream fileOutStream = new FileOutputStream(destFilePath);
byte abyte0[] = new byte[4096];
int length=0;
input = part.getInputStream();
DataInputStream in = new DataInputStream(input);
while ((in != null) && ((length = in.read(abyte0)) != -1)){
fileOutStream.write(abyte0, 0, length);
}
input.close();
in.close();
// my_xlsx_workbook.write(fileOutStream);
fileOutStream.flush();
fileOutStream.close();
}
}
}
提前致谢。