无法使用javamail api从电子邮件中读取附件

时间:2016-10-03 09:26:09

标签: email javamail

无法使用javamail 1.4 api从电子邮件中读取附件。 邮件文件有多个附件,但是当我阅读邮件文件时,显示内容类型:: text / plain

    Properties props = System.getProperties();
    props.put("mail.host", "smtp.abcd.com");
    props.put("mail.transport.protocol", "smtp");

    Session mailSession = Session.getDefaultInstance(props, null);
    InputStream source = new FileInputStream(emlFile);
    MimeMessage message = new MimeMessage(mailSession, source);


    //System.out.println("Subject : " + message.getSubject());
    //System.out.println("From : " + message.getFrom()[0]);
    //System.out.println("--------------");
 // suppose 'message' is an object of type Message
    String contentType = message.getContentType();
    System.out.println(message.getDisposition());
    System.out.println("File name : "+message.getFileName());
    System.out.println("Content type :: "+contentType);
    if (contentType.contains("multipart")) {
        System.out.println("Content type multipart :: "+contentType);
    }

    String mailBody= "";
    Object content = message.getContent();
    //message.get
   // check for string  
    if (content instanceof Multipart) {
        // then check for multipart
        Multipart multiPart = (Multipart) content; 
        procesMultiPart(multiPart);
        }else if (content instanceof String) { 
            mailBody =(String) message.getContent();
        }  

输出: 空值 文件名:null 内容类型:: text / plain 请建议我如何从电子邮件文件中读取附加邮件文件

0 个答案:

没有答案