Jump to content
Changes to the Jaspersoft community edition download ×

zamansafari

Members
  • Posts

    1
  • Joined

  • Last visited

zamansafari's Achievements

Newbie

Newbie (1/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Conversation Starter Rare

Recent Badges

0

Reputation

  1. In my application, I am able to send emails and prepare Jasper Reports. I can send simple text based emails and even attach an image file to the content using Apache Commons-Emails. Also I am able to prepare reports using Jasper Reports with pdf and excel formats. The reported file is downloaded to my pc in any format without any problem. However, my question is I want to send the prepared report via the Apache Commons-Email to a user. That is, the report is ready and I can export its pdf format. I just want the exported pdf path and put it to my mail function. I am a new starter and I couldn't bind the two ready pieces in my app. Could you please shed a light to the matter. Any help would greatly be appreciated. Thank you in very much... Below I am sending the prepared report and email functions so that it may help. In the "sendEmail()" function I just want to put prepared report path instead of image path in the example below. Or any other ways that could help. Prepare Jasper Report function: public void generateReport(String reportPath, @SuppressWarnings("rawtypes") List beanList, String outputFormat, String reportName){try { JasperReport jReport = JasperCompileManager.compileReport(reportPath); JasperPrint jPrint = JasperFillManager.fillReport(jReport, jasperParameter, new JRBeanCollectionDataSource(beanList));} catch (JRException e) { e.printStackTrace();}FacesContext ctx = FacesContext.getCurrentInstance();HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();OutputStream outputStream = null;try { outputStream = response.getOutputStream();} catch (IOException e) { e.printStackTrace();}try { if (outputFormat.equals(OUTPUT_FORMAT_PDF)) { response.setContentType("application/pdf"); response.setHeader("Content-disposition","attachment; filename=" + reportName + ".pdf"); JasperExportManager.exportReportToPdfStream(jPrint, outputStream); } } catch (JRException e) { e.printStackTrace();}try { outputStream.flush(); outputStream.close(); FacesContext.getCurrentInstance().responseComplete();} catch (IOException e) { e.printStackTrace();}[/code]send commons email function: public void sendEmail {// Create the attachmentEmailAttachment attachment = new EmailAttachment();attachment.setPath("mypictures/john.jpg"); // here I want to set the prepared report path so that it could be sent to the user.attachment.setDisposition(EmailAttachment.ATTACHMENT);attachment.setDescription("Picture of John");attachment.setName("John");// Create the email messageMultiPartEmail email = new MultiPartEmail();email.setHostName("smtp.googlemail.com");email.setSmtpPort(465);email.setAuthenticator(new DefaultAuthenticator("username", "password"));email.setSSLOnConnect(true);email.addTo("jdoe@somewhere.org", "John Doe");email.setFrom("me@apache.org", "Me");email.setSubject("The picture");email.setMsg("Here is the picture you wanted");// add the attachmentemail.attach(attachment);// send the emailemail.send();}[/code]
×
×
  • Create New...