0 Replies Latest reply on Mar 7, 2013 12:05 PM by 995448

    file is damaged and could not be repaired, when emailed the PDF Document

      Hi i have the same problem , that what you have resolved, but it doesn't work for me...

      i.e, when i sent a mail from the below code , mail sent but when open it shows "**There was an error in opening this document. the file is damaged and could not be repaired."**

      can u please suggest to over come this problem.. and i m using IBM Websphere 8.

      please advice ....

      thanks alot in advance...

      here is the code :

      AstLogger logger = AstLogger.getInstance();
      logger.info(this.getClass(),"ReportBuilderUtils.sendMail Start....");
      boolean flag = false;
      try {
      javax.naming.InitialContext ctx = new javax.naming.InitialContext();
      javax.mail.Session session = (javax.mail.Session) ctx.lookup(AstProps.getInstance().getWebCollectLoginMailSession());

      Message msg = new MimeMessage(session);
      InternetAddress addressFrom = new InternetAddress(from);
      logger.info(this.getClass(), "Report Builder Utils - Email From :" + from);
      String log = "";
      double tempFilesize=0;
      for(String emailId : recipients) {
      InternetAddress addressTo = new InternetAddress(emailId);
      msg.addRecipient(Message.RecipientType.TO, addressTo);
      log += emailId + ",";
      logger.info(this.getClass(), "Report Builder Utils - Email Recipients :" + log);
      // Setting the Subject and Content Type
      logger.info(this.getClass(), "Report Builder Utils - Email Subject :" + subject);
      msg.setContent(message, "text/plain");
      msg.setHeader("Content-Type", "multipart/mixed");
      MimeBodyPart mbp1 = new MimeBodyPart();
      logger.info(this.getClass(), "Report Builder Utils - Email Message :" + message);
      mbp1.setDataHandler(new DataHandler(new HTMLDataSource(message)));
      Multipart mp = new MimeMultipart();

      // constants to handle the large files
      tempFilesize = tempFile.length();
      logger.info(this.getClass(), "Report Builder Utils - File Size :" +((tempFilesize/(1024*1024))) +"MB.");
      System.out.println("ATTACHMENT_SIZE ==>" +ATTACHMENT_SIZE);
      if(tempFilesize > ATTACHMENT_SIZE){
      flag = false;
      return flag;

      MimeBodyPart mbp_file = new MimeBodyPart();
      mbp_file.setHeader("Content-Type", "application/pdf");
      mbp_file.setHeader("Content-Transfer-Encoding", "Base64");
      mbp_file.setDataHandler(new DataHandler(new FileDataSource(tempFile)));

      System.out.println("Mail Successfully sent to :"+recipients);
      // even tried by placing here
      // mbp_file.setHeader("Content-Transfer-Encoding", "base64"); base64 is not case-sensitive i hope , i read out on some books
      logger.info(this.getClass(), "Report Builder Utils - Email Send successfully...");
      flag = true;
      }catch (Exception e) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      logger.error(this.getClass(), sw.toString());
      AstLogger.getInstance().info(this.getClass(),"ReportBuilderUtils.sendMailAsAttachment End.");
      return flag;

      Edited by: 992445 on Mar 7, 2013 4:05 AM