Skip to content

Commit

Permalink
FINERACT-699 - create new configuration parameters 'fromEmail' and 'f…
Browse files Browse the repository at this point in the history
…romName' and default their values to whatever 'username' is set to.
  • Loading branch information
aasaru committed Feb 11, 2019
1 parent 4784223 commit 0800bb7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -78,7 +80,7 @@ public String getValue() {
}

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,30 @@ public SMTPCredentialsData extractData(final ResultSet rs) throws SQLException,
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void sendToUserAccount(String organisationName, String contactName,
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();
Expand All @@ -74,7 +73,7 @@ public void sendDefinedEmail(EmailDetail emailDetails) {
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 0800bb7

Please sign in to comment.