Merge pull request #516 from aasaru/develop

FINERACT-699 - new configuration parameters 'fromEmail' and 'fromName'
This commit is contained in:
Vishwas Babu A J
2019-02-26 01:03:14 -08:00
committed by GitHub
5 changed files with 77 additions and 15 deletions
@@ -25,13 +25,17 @@ public class SMTPCredentialsData {
private final String host;
private final String port;
private final boolean useTLS;
private final String fromEmail;
private final String fromName;
public SMTPCredentialsData(final String username, final String password, final String host, final String port, final boolean useTLS) {
public SMTPCredentialsData(final String username, final String password, final String host, final String port, final boolean useTLS, String fromEmail, String fromName) {
this.username = username;
this.password = password;
this.host = host;
this.port = port;
this.useTLS = useTLS;
this.fromEmail = fromEmail;
this.fromName = fromName;
}
public String getUsername() {
@@ -54,4 +58,11 @@ public class SMTPCredentialsData {
return useTLS;
}
public String getFromEmail() {
return fromEmail != null ?fromEmail :username;
}
public String getFromName() {
return fromName != null ?fromName :username;
}
}
@@ -34,6 +34,8 @@ public class ExternalServicesConstants {
public static final String SMTP_HOST = "host";
public static final String SMTP_PORT = "port";
public static final String SMTP_USE_TLS = "useTLS";
public static final String SMTP_FROM_EMAIL = "fromEmail";
public static final String SMTP_FROM_NAME = "fromName";
public static final String SMS_SERVICE_NAME = "MESSAGE_GATEWAY";
public static final String SMS_HOST = "host_name";
@@ -78,7 +80,7 @@ public class ExternalServicesConstants {
}
public static enum SMTP_JSON_INPUT_PARAMS {
USERNAME("username"), PASSWORD("password"), HOST("host"), PORT("port"), USETLS("useTLS");
USERNAME("username"), PASSWORD("password"), HOST("host"), PORT("port"), USETLS("useTLS"), FROM_EMAIL("fromEmail"), FROM_NAME("fromName");
private final String value;
@@ -75,21 +75,30 @@ public class ExternalServicesPropertiesReadPlatformServiceImpl implements Extern
String host = null;
String port = "25";
boolean useTLS = false;
String fromEmail = null;
String fromName = null;
while (rs.next()) {
if (rs.getString("name").equalsIgnoreCase(ExternalServicesConstants.SMTP_USERNAME)) {
username = rs.getString("value");
} else if (rs.getString("name").equalsIgnoreCase(ExternalServicesConstants.SMTP_PASSWORD)) {
password = rs.getString("value");
} else if (rs.getString("name").equalsIgnoreCase(ExternalServicesConstants.SMTP_HOST)) {
host = rs.getString("value");
} else if (rs.getString("name").equalsIgnoreCase(ExternalServicesConstants.SMTP_PORT)) {
port = rs.getString("value");
} else if (rs.getString("name").equalsIgnoreCase(ExternalServicesConstants.SMTP_USE_TLS)) {
useTLS = Boolean.parseBoolean(rs.getString("value"));
String name = rs.getString("name");
String value = rs.getString("value");
if (ExternalServicesConstants.SMTP_USERNAME.equalsIgnoreCase(name)) {
username = value;
} else if (ExternalServicesConstants.SMTP_PASSWORD.equalsIgnoreCase(name)) {
password = value;
} else if (ExternalServicesConstants.SMTP_HOST.equalsIgnoreCase(name)) {
host = value;
} else if (ExternalServicesConstants.SMTP_PORT.equalsIgnoreCase(name)) {
port = value;
} else if (ExternalServicesConstants.SMTP_USE_TLS.equalsIgnoreCase(name)) {
useTLS = Boolean.parseBoolean(value);
} else if (ExternalServicesConstants.SMTP_FROM_EMAIL.equalsIgnoreCase(name)) {
fromEmail = value;
} else if (ExternalServicesConstants.SMTP_FROM_NAME.equalsIgnoreCase(name)) {
fromName = value;
}
}
return new SMTPCredentialsData(username, password, host, port, useTLS);
return new SMTPCredentialsData(username, password, host, port, useTLS, fromEmail, fromName);
}
}
@@ -60,7 +60,6 @@ public class GmailBackedPlatformEmailService implements PlatformEmailService {
public void sendDefinedEmail(EmailDetail emailDetails) {
final Email email = new SimpleEmail();
final SMTPCredentialsData smtpCredentialsData = this.externalServicesReadPlatformService.getSMTPCredentials();
final String authuserName = smtpCredentialsData.getUsername();
final String authuser = smtpCredentialsData.getUsername();
final String authpwd = smtpCredentialsData.getPassword();
@@ -74,7 +73,7 @@ public class GmailBackedPlatformEmailService implements PlatformEmailService {
if(smtpCredentialsData.isUseTLS()){
email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
}
email.setFrom(authuser, authuserName);
email.setFrom(smtpCredentialsData.getFromEmail(), smtpCredentialsData.getFromName());
email.setSubject(emailDetails.getSubject());
email.setMsg(emailDetails.getBody());
@@ -0,0 +1,41 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.
--
INSERT INTO `c_external_service_properties` (`name`, `value`, `external_service_id`)
(SELECT
'fromEmail' as name,
value as value,
c_external_service.id as external_service_id
FROM c_external_service_properties
JOIN c_external_service ON c_external_service_properties.external_service_id=c_external_service.id
WHERE c_external_service_properties.name='username'
AND c_external_service.name='SMTP_Email_Account')
UNION ALL
(SELECT
'fromName' as name,
value as value,
c_external_service.id as external_service_id
FROM c_external_service_properties
JOIN c_external_service ON c_external_service_properties.external_service_id=c_external_service.id
WHERE c_external_service_properties.name='username'
AND c_external_service.name='SMTP_Email_Account');