String emailSubject = (String) properties.get("subject");
String emailMessage = (String) properties.get("message");
String isHtml = (String) properties.get("isHtml");
WorkflowAssignment wfAssignment = (WorkflowAssignment) properties.get("workflowAssignment");
AppDefinition appDef = (AppDefinition) properties.get("appDef");
try {
Map<String, String> replaceMap = null;
if ("true".equalsIgnoreCase(isHtml)) {
replaceMap = new HashMap<String, String>();
replaceMap.put("\\n", "<br/>");
}
emailSubject = WorkflowUtil.processVariable(emailSubject, formDataTable, wfAssignment);
emailMessage = AppUtil.processHashVariable(emailMessage, wfAssignment, null, replaceMap);
smtpHost = AppUtil.processHashVariable(smtpHost, wfAssignment, null, null);
smtpPort = AppUtil.processHashVariable(smtpPort, wfAssignment, null, null);
smtpUsername = AppUtil.processHashVariable(smtpUsername, wfAssignment, null, null);
smtpPassword = AppUtil.processHashVariable(smtpPassword, wfAssignment, null, null);
security = AppUtil.processHashVariable(security, wfAssignment, null, null);
// create the email message
final HtmlEmail email = new HtmlEmail();
email.setHostName(smtpHost);
if (smtpPort != null && smtpPort.length() != 0) {
email.setSmtpPort(Integer.parseInt(smtpPort));
}
if (smtpUsername != null && !smtpUsername.isEmpty()) {
if (smtpPassword != null) {
smtpPassword = SecurityUtil.decrypt(smtpPassword);
}
email.setAuthentication(smtpUsername, smtpPassword);
}
if(security!= null){
if(security.equalsIgnoreCase("SSL") ){
email.setSSL(true);
}else if(security.equalsIgnoreCase("TLS")){
email.setTLS(true);
}
}
if (cc != null && cc.length() != 0) {
Collection<String> ccs = AppUtil.getEmailList(null, cc, wfAssignment, appDef);
for (String address : ccs) {
email.addCc(address);
}
}
final String fromStr = WorkflowUtil.processVariable(from, formDataTable, wfAssignment);
email.setFrom(fromStr);
email.setSubject(emailSubject);
email.setCharset("UTF-8");
if ("true".equalsIgnoreCase(isHtml)) {
email.setHtmlMsg(emailMessage);
} else {
email.setMsg(emailMessage);
}
String emailToOutput = "";
if ((toParticipantId != null && toParticipantId.trim().length() != 0) || (toSpecific != null && toSpecific.trim().length() != 0)) {
Collection<String> tss = AppUtil.getEmailList(toParticipantId, toSpecific, wfAssignment, appDef);
for (String address : tss) {
email.addTo(address);
emailToOutput += address + ", ";
}
} else {
throw new PluginException("no email specified");
}
final String to = emailToOutput;
final String profile = DynamicDataSourceManager.getCurrentProfile();
//handle file attachment
String formDefId = (String) properties.get("formDefId");
Object[] fields = null;
if (properties.get("fields") instanceof Object[]){
fields = (Object[]) properties.get("fields");
}
if (formDefId != null && !formDefId.isEmpty() && fields != null && fields.length > 0) {
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
FormData formData = new FormData();
String primaryKey = appService.getOriginProcessId(wfAssignment.getProcessId());
formData.setPrimaryKeyValue(primaryKey);
Form loadForm = appService.viewDataForm(appDef.getId(), appDef.getVersion().toString(), formDefId, null, null, null, formData, null, null);
for (Object o : fields) {
Map mapping = (HashMap) o;