private boolean sendDocumentViaMail(File pdfFile, Properties metadata) {
if (!Boolean.parseBoolean(AppProperties.getProperty(MailKeys.PROP_KEY_SHALL_SEND_MAIL))) {
return true;
}
SendHtmlMailUtils mail = new SendHtmlMailUtils();
if (Boolean.parseBoolean(AppProperties.getProperty(MailKeys.PROP_KEY_ADD_DOCUMENT_AS_ATTACHMENT))) {
mail.addAttachment(pdfFile);
}
mail.addTO(AppProperties.getProperty(MailKeys.PROP_KEY_RECEIVER_MAIL_ADDRESS));
mail.setFrom(AppProperties.getProperty(MailKeys.PROP_KEY_SENDER_MAIL_ADDRESS));
mail.setLogin(AppProperties.getProperty(MailKeys.PROP_KEY_SENDER_MAIL_ADDRESS));
mail.setPassword(AppProperties.getProperty(MailKeys.PROP_KEY_SENDER_MAIL_PW));
mail.setPop3Host(AppProperties.getProperty(MailKeys.PROP_KEY_SENDER_POP3_SERVER));
mail.setSmtp(AppProperties.getProperty(MailKeys.PROP_KEY_SENDER_SMTP_SERVER),
Integer.parseInt(AppProperties.getProperty(MailKeys.PROP_KEY_SENDER_SMTP_PORT)));
String docID = metadata.getProperty(Metadata.DOCUMENT_ID);
mail.setSubject("::from::OCR:: " + docID);
String link = "";
if (Boolean.parseBoolean(AppProperties.getProperty(PROP_KEY_DOCUMENT_SERVER_SHALL_USE))) {
String serverName = AppProperties.getProperty(PROP_KEY_DOCUMENT_SERVER_NAME);
String port = AppProperties.getProperty(PROP_KEY_DOCUMENT_SERVER_PORT);
// String serverMethod = DocumentServer.DOCUMENT_RETRIEVAL_METHOD;
String serverMethod = new DocumentRetrievalWebsite().getWebsiteName();
String docParm = WebsiteVariableConstants.varnameDocumentID + "=" + docID;
String href = "http://" + serverName + ":" + port + "/" + serverMethod + "?" + docParm + "";
link = "<p><a href=\"" + href + "\">Link zu " + docID + "</a></p>";
}
if (Boolean.parseBoolean(AppProperties.getProperty(MailKeys.PROP_KEY_SET_FULLTEXT_INTO_MAIL_BODY))) {
String fulltext = metadata.getProperty(Metadata.FULLTEXT);
String htmltext = HtmlFormatter.getHtmlString(fulltext, false, false);
mail.setText(link + "<p>" + htmltext + "</p>");
}
try {
mail.sendMail();
return true;
}
catch (MessagingException e) {
LogUtils.log(e);
return false;