|
8 | 8 | import com.sismics.docs.core.dao.dto.UserDto; |
9 | 9 | import com.sismics.docs.core.model.context.AppContext; |
10 | 10 | import com.sismics.docs.core.model.jpa.Config; |
11 | | -import com.sismics.docs.core.util.ConfigUtil; |
12 | 11 | import freemarker.template.Configuration; |
13 | 12 | import freemarker.template.DefaultObjectWrapperBuilder; |
14 | 13 | import freemarker.template.Template; |
@@ -91,19 +90,27 @@ private static void sendEmail(String templateName, UserDto recipientUser, String |
91 | 90 | email.setCharset(StandardCharsets.UTF_8.name()); |
92 | 91 | ConfigDao configDao = new ConfigDao(); |
93 | 92 |
|
94 | | - // Hostname |
| 93 | + // Hostname: env first, then DB |
95 | 94 | String envHostname = System.getenv(Constants.SMTP_HOSTNAME_ENV); |
96 | | - if (Strings.isNullOrEmpty(envHostname)) { |
97 | | - email.setHostName(ConfigUtil.getConfigStringValue(ConfigType.SMTP_HOSTNAME)); |
98 | | - } else { |
| 95 | + if (!Strings.isNullOrEmpty(envHostname)) { |
99 | 96 | email.setHostName(envHostname); |
| 97 | + } else { |
| 98 | + Config hostnameConfig = configDao.getById(ConfigType.SMTP_HOSTNAME); |
| 99 | + if (hostnameConfig != null) { |
| 100 | + email.setHostName(hostnameConfig.getValue()); |
| 101 | + } |
100 | 102 | } |
101 | 103 |
|
102 | | - // Port |
103 | | - int port = ConfigUtil.getConfigIntegerValue(ConfigType.SMTP_PORT); |
| 104 | + // Port: env first, then DB, default 587 |
| 105 | + int port = 587; |
104 | 106 | String envPort = System.getenv(Constants.SMTP_PORT_ENV); |
105 | 107 | if (!Strings.isNullOrEmpty(envPort)) { |
106 | | - port = Integer.valueOf(envPort); |
| 108 | + port = Integer.parseInt(envPort); |
| 109 | + } else { |
| 110 | + Config portConfig = configDao.getById(ConfigType.SMTP_PORT); |
| 111 | + if (portConfig != null) { |
| 112 | + port = Integer.parseInt(portConfig.getValue()); |
| 113 | + } |
107 | 114 | } |
108 | 115 | email.setSmtpPort(port); |
109 | 116 | if (port == 465) { |
@@ -138,8 +145,16 @@ private static void sendEmail(String templateName, UserDto recipientUser, String |
138 | 145 | } |
139 | 146 | } |
140 | 147 |
|
141 | | - // From email address (defined only by configuration value in the database) |
142 | | - email.setFrom(ConfigUtil.getConfigStringValue(ConfigType.SMTP_FROM), appName); |
| 148 | + // From email address: env first, then DB |
| 149 | + String envFrom = System.getenv(Constants.SMTP_FROM_ENV); |
| 150 | + if (!Strings.isNullOrEmpty(envFrom)) { |
| 151 | + email.setFrom(envFrom, appName); |
| 152 | + } else { |
| 153 | + Config fromConfig = configDao.getById(ConfigType.SMTP_FROM); |
| 154 | + if (fromConfig != null) { |
| 155 | + email.setFrom(fromConfig.getValue(), appName); |
| 156 | + } |
| 157 | + } |
143 | 158 |
|
144 | 159 | // Locale (defined only by environment variable) |
145 | 160 | java.util.Locale userLocale = LocaleUtil.getLocale(System.getenv(Constants.DEFAULT_LANGUAGE_ENV)); |
|
0 commit comments