From fc3f503ac8c9c9cc4948ef0a8be874a2a23f0408 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Mon, 21 Dec 2015 22:21:56 +0100 Subject: [PATCH] Minor - small addition to SendMailSSL refactor --- src/main/java/fr/xephi/authme/mail/SendMailSSL.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/mail/SendMailSSL.java b/src/main/java/fr/xephi/authme/mail/SendMailSSL.java index b2903f0ee..3b6dde845 100644 --- a/src/main/java/fr/xephi/authme/mail/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/mail/SendMailSSL.java @@ -32,7 +32,6 @@ public class SendMailSSL { } public void main(final PlayerAuth auth, final String newPass) { - final int port = Settings.getMailPort; final String mailText = replaceMailTags(Settings.getMailText, plugin, auth, newPass); Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @@ -42,7 +41,6 @@ public class SendMailSSL { HtmlEmail email; try { email = initializeMail(auth); - setPropertiesForPort(port, email); } catch (EmailException e) { ConsoleLogger.showError("Failed to create email with the given settings: " + StringUtils.formatException(e)); @@ -87,16 +85,17 @@ public class SendMailSSL { private static HtmlEmail initializeMail(PlayerAuth auth) throws EmailException { String senderName; - if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) { + if (StringUtils.isEmpty(Settings.getmailSenderName)) { senderName = Settings.getmailAccount; } else { senderName = Settings.getmailSenderName; } String senderMail = Settings.getmailAccount; String mailPassword = Settings.getmailPassword; + int port = Settings.getMailPort; HtmlEmail email = new HtmlEmail(); - email.setSmtpPort(Settings.getMailPort); + email.setSmtpPort(port); email.setHostName(Settings.getmailSMTP); email.addTo(auth.getEmail()); email.setFrom(senderMail, senderName); @@ -105,6 +104,8 @@ public class SendMailSSL { String password = !Settings.emailOauth2Token.isEmpty() ? "" : mailPassword; email.setAuthenticator(new DefaultAuthenticator(senderMail, password)); } + + setPropertiesForPort(email, port); return email; } @@ -133,7 +134,7 @@ public class SendMailSSL { .replace("", newPass); } - private static void setPropertiesForPort(int port, HtmlEmail email) throws EmailException { + private static void setPropertiesForPort(HtmlEmail email, int port) throws EmailException { switch (port) { case 587: email.setStartTLSEnabled(true);