Get email access for POP 3 received as winmail.dat

When I try to get a link to POP 3 mail, I get them as winmail.dat, and not the original attached file name. How to get the original file name?

for (int i = 0; i < multipart.getCount(); i++) { BodyPart bodyPart = multipart.getBodyPart(i); if(!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition())) { //do something } else { bodyPart.getFileName(); // here only get the winmail.dat } } 
+1
source share
1 answer

This is part of the Exchange settings, and unfortunately, you will need to extract the original content from WinMail.dat using JTNEF .

"The Java TNEF package is an open source TNEF message handler implementation that can be used as a command-line utility or integrated with Java-based mail applications to retrieve the original content of the message."

This can be found in third-party JavaMail tools.

Alternatively and one that looks simpler, POI-HMEF

Sample extraction:

 public void extract(String winmailFilename, String directoryName) throws Exception { HMEFContentsExtractor ext = new HMEFContentsExtractor(new File(winmailFilename)); File dir = new File(directoryName); File rtf = new File(dir, "message.rtf"); if(! dir.exists()) { throw new FileNotFoundException("Output directory " + dir.getName() + " not found"); } System.out.println("Extracting..."); ext.extractMessageBody(rtf); ext.extractAttachments(dir); System.out.println("Extraction completed"); } 

There is also a sample for printing content here .

+2
source

Source: https://habr.com/ru/post/1274198/


All Articles