From e564453df7736da4e72b0f3b0ffc8eeccb4174ce Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Sun, 21 Jun 2015 13:45:26 +0200 Subject: [PATCH] Change how Exception is thrown on failed to send mail --- pom.xml | 14 +++++------ .../java/fr/xephi/authme/SendMailSSL.java | 23 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 6139968c..6ea59fa1 100644 --- a/pom.xml +++ b/pom.xml @@ -203,14 +203,14 @@ - com.onarandombox.multiversecore - Multiverse-Core - 2.5 - jar - compile - + com.onarandombox.multiversecore + Multiverse-Core + 2.5 + jar + compile + - + net.ess3 Essentials diff --git a/src/main/java/fr/xephi/authme/SendMailSSL.java b/src/main/java/fr/xephi/authme/SendMailSSL.java index a2816016..c1d433ad 100644 --- a/src/main/java/fr/xephi/authme/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/SendMailSSL.java @@ -3,8 +3,8 @@ package fr.xephi.authme; import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Properties; + import javax.mail.Message; -import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; @@ -44,13 +44,13 @@ public class SendMailSSL { props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", String.valueOf(Settings.getMailPort)); - Session session = Session.getInstance(props, new javax.mail.Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(Settings.getmailAccount, Settings.getmailPassword); - } - }); - try { + Session session = Session.getInstance(props, new javax.mail.Authenticator() { + + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(Settings.getmailAccount, Settings.getmailPassword); + } + }); final Message message = new MimeMessage(session); try { message.setFrom(new InternetAddress(Settings.getmailAccount, sendername)); @@ -66,19 +66,20 @@ public class SendMailSSL { text = text.replace("", newPass); message.setContent(text, "text/html"); Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override public void run() { try { Transport.send(message); - } catch (MessagingException e) { - e.printStackTrace(); + } catch (Exception e) { + ConsoleLogger.showError("Some error appears while trying to send mail to " + auth.getEmail()); } } }); if (!Settings.noConsoleSpam) ConsoleLogger.info("Email sent to : " + auth.getNickname()); - } catch (MessagingException e) { - throw new RuntimeException(e); + } catch (Exception e) { + ConsoleLogger.showError("Some error appears while trying to send mail to " + auth.getEmail()); } } }