final MapiMessage msg = MapiMessage.fromMailMessage(emailFilename);
final String dataDir = "./AsposeTemp/";
Files.createDirectories(Paths.get(dataDir));
for (int i = 0; i < msg.getAttachments().size(); i++) {
//Set a reference to the MapiAttachment object
final MapiAttachment outlookMessageAttachment = (MapiAttachment) msg.getAttachments().get_Item(i);
//Display attachment type
System.out.println("Att Type : " + outlookMessageAttachment.getMimeTag());
//Display attached file name
System.out.println("File Name : " + outlookMessageAttachment.getLongFileName());
//Save attachment to the disk
outlookMessageAttachment.save(dataDir + outlookMessageAttachment.getDisplayName());
}
when I set a breakpoint at “msg.getAttachments().size()”, its actually value is 3, although my test Email has only 2 attachment files.
The console output is
Att Type : application/octet-stream
File Name : image001.jpg
Att Type : application/octet-stream
File Name : Original_Message.eml
Att Type : image/jpeg
File Name : image001.jpg
Thank you for your response, however, is there a way to download only such files in attachments, but not in message body? In this case, only 1 and 2 should be downloaded, not 3.
In response to your question, let me inform you that in order to distinguish between normal attachments and inline attachments, the MapiAttachment class has a method isInline() that returns ‘false’ if the attachment is normal.
The code sample below will show you how it works:
for (int i = 0; i < msg.getAttachments().size(); i++) {
//Set a reference to the MapiAttachment object
final MapiAttachment outlookMessageAttachment = (MapiAttachment) msg.getAttachments().get_Item(i);
if (!outlookMessageAttachment.isInline()) {
//Display attachment type
System.out.println("Att Type : " + outlookMessageAttachment.getMimeTag());
//Display attached file name
System.out.println("File Name : " + outlookMessageAttachment.getLongFileName());
//Save attachment to the disk
outlookMessageAttachment.save(dataDir + outlookMessageAttachment.getDisplayName());
}
}
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.