88 if(contacts ==
null)
return;
89 Application app = Application.getApplication();
90 SignedReport sr =
new SignedReport();
91 sr.setCertificateStore(certificateStore);
92 if(
new File(ElephantContext.getRealPath(jasperFile)).exists()) {
93 sr.setSrc(jasperFile);
95 sr.setSrc(defaultFile);
97 sr.setParameters(parameters);
98 sr.setDatasource(dataSource);
100 File attach = File.createTempFile(
"attach_",
"_mail");
101 FileOutputStream fos =
new FileOutputStream(attach);
102 InputStream is = sr.getReport().getStreamData();
104 byte[] bytes =
new byte[1024];
105 while ((read = is.read(bytes)) != -1) {
106 fos.write(bytes, 0, read);
111 StringBuilder sb =
new StringBuilder();
112 for(IContact c : contacts) {
113 String email = c.getConnector(IUser.CONNECTOR_EMAIL);
114 if(Contacts.isValidEmail(email)) {
115 MailProvider mp = MailProviders.instance().getProvider(certificateStore);
116 MailMessage mm = MailMessage.of(mp);
117 mm.addTo(c.getEmail(), c.getName());
118 sb.append(email).append(
": ").append(c.getName()).append(
"\n");
119 mm.setFrom(mp.getFrom().getMail(), ElephantContext.getSiteName());
120 mm.setSubject(ElephantContext.getSiteName() +
": " + title);
122 "<p><i>" + I_.get(
"Automatically generated") +
"</i></p>" +
123 "<p><b>" + ElephantContext.getSiteName() +
"</b>: " + I_.get(
"Document") +
"</p>");
124 mm.attach(attach.getAbsolutePath(), ElephantContext.getSiteName() +
" " + I_.get(
"Document"), title +
".pdf");
129 if(sb.length() > 0) {
130 Messages.info(I_.get(
"Send documents")).add(I_.get(
"Sent")).paragraph().add(sb.toString()).show();
132 Messages.error(I_.get(
"Send documents")).add(I_.get(
"Nothing was sent")).show();
134 }
catch (Exception ex) {