I have tried the following code to save the attachments from mail.
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
part.saveFile(myDirectory + File.separator + fileName);
It worked for save the attachments but in case if "myDirectory" already contains the file named "file1.pdf" even mail contains same "file1.pdf" with different content it replaces the existing file.
In my case, i need to save both files into directory(file1.pdf,file1.pdf(1))
can anyone suggest me the way to do that?
Check that the file already exists using the java.io.File.exists method, and if it does exist then choose a different name for the file before saving it.