dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30203
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15312: Email settings, made the email from address configurable
------------------------------------------------------------
revno: 15312
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-20 17:16:46 +0200
message:
Email settings, made the email from address configurable
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-05-15 16:58:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-05-20 15:16:46 +0000
@@ -68,6 +68,7 @@
final String KEY_EMAIL_USERNAME = "keyEmailUsername";
final String KEY_EMAIL_PASSWORD = "keyEmailPassword";
final String KEY_EMAIL_TLS = "keyEmailTls";
+ final String KEY_EMAIL_SENDER = "keyEmailSender";
final String KEY_SCHEDULED_PERIOD_TYPES = "keyScheduledPeriodTypes";
final String KEY_SCHEDULED_TASKS = "keySchedTasks";
final String KEY_ORGUNITGROUPSET_AGG_LEVEL = "orgUnitGroupSetAggregationLevel";
@@ -145,6 +146,8 @@
String getEmailPassword();
boolean getEmailTls();
+
+ String getEmailSender();
boolean accountRecoveryEnabled();
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2014-05-08 07:37:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java 2014-05-20 15:16:46 +0000
@@ -44,6 +44,8 @@
import org.hisp.dhis.user.UserService;
import org.springframework.scheduling.annotation.Async;
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+
/**
* @author Lars Helge Overland
*/
@@ -52,7 +54,7 @@
{
private static final Log log = LogFactory.getLog( EmailMessageSender.class );
private static final String FROM_ADDRESS = "noreply@xxxxxxxxx";
- private static final String FROM_NAME = "DHIS2 Message [No reply]";
+ private static final String FROM_NAME = "DHIS 2 Message [No reply]";
private static final String SUBJECT_PREFIX = "[DHIS2] ";
private static final String LB = System.getProperty( "line.separator" );
@@ -90,6 +92,7 @@
String username = systemSettingManager.getEmailUsername();
String password = systemSettingManager.getEmailPassword();
boolean tls = systemSettingManager.getEmailTls();
+ String from = systemSettingManager.getEmailSender();
if ( hostName == null )
{
@@ -104,7 +107,7 @@
try
{
- Email email = getEmail( hostName, port, username, password, tls );
+ Email email = getEmail( hostName, port, username, password, tls, from );
email.setSubject( SUBJECT_PREFIX + subject );
email.setMsg( text );
@@ -141,12 +144,12 @@
return null;
}
- private Email getEmail( String hostName, int port, String username, String password, boolean tls )
+ private Email getEmail( String hostName, int port, String username, String password, boolean tls, String sender )
throws EmailException
{
Email email = new SimpleEmail();
email.setHostName( hostName );
- email.setFrom( FROM_ADDRESS, FROM_NAME );
+ email.setFrom( defaultIfEmpty( sender, FROM_ADDRESS ), FROM_NAME );
email.setSmtpPort( port );
email.setTLS( true );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2014-05-15 16:58:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2014-05-20 15:16:46 +0000
@@ -159,7 +159,12 @@
{
return (Boolean) getSystemSetting( KEY_EMAIL_TLS, true );
}
-
+
+ public String getEmailSender()
+ {
+ return StringUtils.trimToNull( (String) getSystemSetting( KEY_EMAIL_SENDER ) );
+ }
+
public boolean accountRecoveryEnabled()
{
return (Boolean) getSystemSetting( KEY_ACCOUNT_RECOVERY, false );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java 2014-05-20 15:16:46 +0000
@@ -88,6 +88,13 @@
{
return smtpTls;
}
+
+ private String emailSender;
+
+ public String getEmailSender()
+ {
+ return emailSender;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -105,6 +112,8 @@
smtpTls = systemSettingManager.getEmailTls();
+ emailSender = systemSettingManager.getEmailSender();
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java 2014-05-20 15:16:46 +0000
@@ -92,6 +92,13 @@
this.smtpTls = smtpTls;
}
+ private String emailSender;
+
+ public void setEmailSender( String emailSender )
+ {
+ this.emailSender = emailSender;
+ }
+
private String message;
public String getMessage()
@@ -122,6 +129,8 @@
systemSettingManager.saveSystemSetting( KEY_EMAIL_TLS, smtpTls );
+ systemSettingManager.saveSystemSetting( KEY_EMAIL_SENDER, emailSender );
+
message = i18n.getString( "settings_updated" );
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2014-05-15 13:16:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2014-05-20 15:16:46 +0000
@@ -8,7 +8,7 @@
smtp_settings=Email settings
approval_settings=Approval settings
host_name=Host name
-username=User name
+username=Username
password=Password
application_title=Application title
dhis-web-maintenance-settings=Settings
@@ -88,6 +88,7 @@
multi_organisation_unit_forms=Enable multi-organisation unit forms
port=Port
tls=TLS
+email_sender=Email sender
allows_html=allows HTML
application_footer=Application footer
user_credentials_expires=Require user account password change
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm 2013-11-04 13:21:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemEmailSettings.vm 2014-05-20 15:16:46 +0000
@@ -6,7 +6,8 @@
smtpPort: getFieldValue( 'smtpPort' ),
smtpUsername: getFieldValue( 'smtpUsername' ),
smtpPassword: getFieldValue( 'smtpPassword' ),
- smtpTls: $( '#smtpTls' ).is( ':checked' )
+ smtpTls: $( '#smtpTls' ).is( ':checked' ),
+ emailSender: getFieldValue( 'emailSender' )
}, function( json ) {
if ( json.response == "success" ) {
setHeaderDelayMessage( json.message );
@@ -24,7 +25,7 @@
<div class="settingLabel">$i18n.getString( "host_name" ) <span class="tipText">(e.g. smtp.gmail.com, localhost)</span></div>
-<div class="setting"><input type="text" id="smtpHostName" name="smtpHostName" value="$!smtpHostName"/></div>
+<div class="setting"><input type="text" id="smtpHostName" name="smtpHostName" value="$!smtpHostName"></div>
<div class="settingLabel">$i18n.getString( "port" )</div>
@@ -38,17 +39,21 @@
<div class="settingLabel">$i18n.getString( "username" )</div>
-<div class="setting"><input type="text" id="smtpUsername" name="smtpUsername" value="$!smtpUsername" autocomplete="off"/></div>
+<div class="setting"><input type="text" id="smtpUsername" name="smtpUsername" value="$!smtpUsername" autocomplete="off"></div>
<div class="settingLabel">$i18n.getString( "password" )</div>
-<div class="setting"><input type="password" id="smtpPassword" name="smtpPassword" value="$!smtpPassword" autocomplete="off"/></div>
+<div class="setting"><input type="password" id="smtpPassword" name="smtpPassword" value="$!smtpPassword" autocomplete="off"></div>
<div class="setting">
<input type="checkbox" id="smtpTls" name="smtpTls" value="true"#if( $smtpTls ) checked="checked"#end>
<label for="smtpTls">$i18n.getString( "tls" )</label>
</div>
-<div class="setting"><input type="button" value="$i18n.getString( 'save' )" style="width:10em"/></div>
+<div class="settingLabel">$i18n.getString( "email_sender" )</div>
+
+<div class="setting"><input type="text" id="emailSender" name="emailSender" value="$!emailSender" autocomplete="off" placeholder="noreply@dhis2.org"></div>
+
+<div class="setting"><input type="button" value="$i18n.getString( 'save' )" style="width:10em"></div>
</form>