get email attatchment for POP 3 received as winmail.dat

萝らか妹 提交于 2020-01-05 08:18:12

问题


When I try to get attatchment from POP 3 mail, I am getting them as winmail.dat, not the original attached file name. How can I 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:


This is part of the Exchange Settings, and sadly you going to need to extract the original contents from the WinMail.dat using JTNEF.

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

This is found on the JavaMail's third party tools.

As alternative and what looks simpler is 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 the contents here.



来源:https://stackoverflow.com/questions/14949671/get-email-attatchment-for-pop-3-received-as-winmail-dat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!