Skip to content

Commit f7d5cf8

Browse files
committed
extract constants for property keys
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent c1f21e9 commit f7d5cf8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
*/
6161
public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
6262

63+
public static final String MAIL_SMTP_HOST_PK = "mail.smtp.host";
64+
public static final String MAIL_SMTP_PORT_PK = "mail.smtp.port";
65+
public static final String MAIL_SMTP_LOCALHOST_PK = "mail.smtp.localhost";
66+
public static final String MAIL_SMTP_AUTH_PK = "mail.smtp.auth";
67+
public static final String MAIL_SMTP_STARTTLS_ENABLE_PK = "mail.smtp.starttls.enable";
68+
public static final String MAIL_TRANSPORT_PROTOCOL_PK = "mail.transport.protocol";
69+
public static final String MAIL_SMTP_SSL_ENABLE_PK = "mail.smtp.ssl.enable";
6370
static InternetAddress[] EMPTY_IA_ARRAY = new InternetAddress[0];
6471
// ~ 14 days
6572
static final long MAX_DELAY_BETWEEN_STATUS_MESSAGES = 1228800 * CoreConstants.MILLIS_IN_ONE_SECOND;
@@ -146,31 +153,32 @@ private Session lookupSessionInJNDI() {
146153
private Session buildSessionFromProperties() {
147154
Properties props = new Properties(OptionHelper.getSystemProperties());
148155
if (smtpHost != null) {
149-
props.put("mail.smtp.host", smtpHost);
156+
props.put(MAIL_SMTP_HOST_PK, smtpHost);
150157
}
151-
props.put("mail.smtp.port", Integer.toString(smtpPort));
158+
159+
props.put(MAIL_SMTP_PORT_PK, Integer.toString(smtpPort));
152160

153161
if (localhost != null) {
154-
props.put("mail.smtp.localhost", localhost);
162+
props.put(MAIL_SMTP_LOCALHOST_PK, localhost);
155163
}
156164

157165
LoginAuthenticator loginAuthenticator = null;
158166

159167
if (!OptionHelper.isNullOrEmptyOrAllSpaces(username)) {
160168
loginAuthenticator = new LoginAuthenticator(username, password);
161-
props.put("mail.smtp.auth", "true");
169+
props.put(MAIL_SMTP_AUTH_PK, "true");
162170
}
163171

164172
if (isSTARTTLS() && isSSL()) {
165173
addError("Both SSL and StartTLS cannot be enabled simultaneously");
166174
} else {
167175
if (isSTARTTLS()) {
168176
// see also http://jira.qos.ch/browse/LOGBACK-193
169-
props.put("mail.smtp.starttls.enable", "true");
170-
props.put("mail.transport.protocol", "true");
177+
props.put(MAIL_SMTP_STARTTLS_ENABLE_PK, "true");
178+
props.put(MAIL_TRANSPORT_PROTOCOL_PK, "true");
171179
}
172180
if (isSSL()) {
173-
props.put("mail.smtp.ssl.enable", "true");
181+
props.put(MAIL_SMTP_SSL_ENABLE_PK, "true");
174182
}
175183
}
176184

0 commit comments

Comments
 (0)