use of org.activiti.engine.cfg.MailServerInfo in project Activiti by Activiti.
the class MailActivityBehavior method setMailServerProperties.
protected void setMailServerProperties(Email email, String tenantId) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
boolean isMailServerSet = false;
if (tenantId != null && tenantId.length() > 0) {
if (processEngineConfiguration.getMailSessionJndi(tenantId) != null) {
setEmailSession(email, processEngineConfiguration.getMailSessionJndi(tenantId));
isMailServerSet = true;
} else if (processEngineConfiguration.getMailServer(tenantId) != null) {
MailServerInfo mailServerInfo = processEngineConfiguration.getMailServer(tenantId);
String host = mailServerInfo.getMailServerHost();
if (host == null) {
throw new ActivitiException("Could not send email: no SMTP host is configured for tenantId " + tenantId);
}
email.setHostName(host);
email.setSmtpPort(mailServerInfo.getMailServerPort());
email.setSSLOnConnect(mailServerInfo.isMailServerUseSSL());
email.setStartTLSEnabled(mailServerInfo.isMailServerUseTLS());
String user = mailServerInfo.getMailServerUsername();
String password = mailServerInfo.getMailServerPassword();
if (user != null && password != null) {
email.setAuthentication(user, password);
}
isMailServerSet = true;
}
}
if (!isMailServerSet) {
String mailSessionJndi = processEngineConfiguration.getMailSessionJndi();
if (mailSessionJndi != null) {
setEmailSession(email, mailSessionJndi);
} else {
String host = processEngineConfiguration.getMailServerHost();
if (host == null) {
throw new ActivitiException("Could not send email: no SMTP host is configured");
}
email.setHostName(host);
int port = processEngineConfiguration.getMailServerPort();
email.setSmtpPort(port);
email.setSSLOnConnect(processEngineConfiguration.getMailServerUseSSL());
email.setStartTLSEnabled(processEngineConfiguration.getMailServerUseTLS());
String user = processEngineConfiguration.getMailServerUsername();
String password = processEngineConfiguration.getMailServerPassword();
if (user != null && password != null) {
email.setAuthentication(user, password);
}
}
}
}
use of org.activiti.engine.cfg.MailServerInfo in project Activiti by Activiti.
the class MailActivityBehavior method setFrom.
protected void setFrom(Email email, String from, String tenantId) {
String fromAddress = null;
if (from != null) {
fromAddress = from;
} else {
// use default configured from address in process engine config
if (tenantId != null && tenantId.length() > 0) {
Map<String, MailServerInfo> mailServers = Context.getProcessEngineConfiguration().getMailServers();
if (mailServers != null && mailServers.containsKey(tenantId)) {
MailServerInfo mailServerInfo = mailServers.get(tenantId);
fromAddress = mailServerInfo.getMailServerDefaultFrom();
}
}
if (fromAddress == null) {
fromAddress = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
}
}
try {
email.setFrom(fromAddress);
} catch (EmailException e) {
throw new ActivitiException("Could not set " + from + " as from address in email", e);
}
}
Aggregations