代码之家  ›  专栏  ›  技术社区  ›  Aaron Saunders

从groovy中的gmail附件创建pdf时出错

  •  0
  • Aaron Saunders  · 技术社区  · 15 年前

    我正尝试使用Java邮件API下载Gmail中的附件,这是代码片段。

    System.setProperty("mail.mime.base64.ignoreerrors", "true")
    
    if ( mp.getBodyPart(i).disposition == "ATTACHMENT" ) {
        def OutputStream out
        try {
            out = new BufferedOutputStream(newFileOutputStream("/_1test.pdf"));             
            out.write(IOUtils.toByteArray(mp.getBodyPart(i).getInputStream()));
        } finally {
            if (out != null) out.close();
        }
     }
    

    代码运行良好,没有异常,但创建的文件不能在Acrobat中打开。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Aaron Saunders    15 年前

    发现问题,需要将partialfetch标志设置为false…

    props.put("mail.imap.partialfetch", "false");