diff --git a/org.adempiere.base.process/src/org/compiere/process/EMailTest.java b/org.adempiere.base.process/src/org/compiere/process/EMailTest.java index ebf3473de9..946eb9a6c1 100644 --- a/org.adempiere.base.process/src/org/compiere/process/EMailTest.java +++ b/org.adempiere.base.process/src/org/compiere/process/EMailTest.java @@ -110,7 +110,7 @@ public class EMailTest extends SvrProcess if (! from.contains("@")) from = "test@" + from; email.setFrom(from); - String msg = email.send(); + String msg = email.sendEx(); if (EMail.SENT_OK.equals (msg)) { if (log.isLoggable(Level.INFO)) log.info("Sent Test EMail to " + client.getRequestEMail()); diff --git a/org.adempiere.base/src/org/compiere/util/EMail.java b/org.adempiere.base/src/org/compiere/util/EMail.java index 0482509cf9..b60e74324d 100644 --- a/org.adempiere.base/src/org/compiere/util/EMail.java +++ b/org.adempiere.base/src/org/compiere/util/EMail.java @@ -247,7 +247,32 @@ public final class EMail implements Serializable * Send Mail direct * @return OK or error message */ - public String send () + public String send() + { + String msg; + try { + msg = send(false); + } catch (Exception e) { + msg = e.getLocalizedMessage(); + } + return msg; + } + + /** + * Send Mail direct + * @return OK or error message + */ + public String sendEx() throws Exception + { + return send(true); + } + + /** + * Send Mail direct + * @return OK or error message + * @throws Exception + */ + public String send(boolean throwException) throws Exception { if (!m_forceUseTenantSmtp && getFrom() != null) { MSMTP smtp = MSMTP.get(m_ctx, Env.getAD_Client_ID(m_ctx), getFrom().getAddress()); @@ -325,6 +350,8 @@ public final class EMail implements Serializable } catch (SecurityException se) { + if (throwException) + throw se; log.log(Level.WARNING, "Auth=" + m_auth + " - " + se.toString()); m_sentMsg = se.toString(); Env.getCtx().put(EMAIL_SEND_MSG, m_sentMsg); @@ -332,6 +359,8 @@ public final class EMail implements Serializable } catch (Exception e) { + if (throwException) + throw e; log.log(Level.SEVERE, "Auth=" + m_auth, e); m_sentMsg = e.toString(); Env.getCtx().put(EMAIL_SEND_MSG, m_sentMsg); @@ -420,6 +449,8 @@ public final class EMail implements Serializable } catch (MessagingException me) { + if (throwException) + throw me; me.printStackTrace(); Exception ex = me; StringBuilder sb = new StringBuilder("(ME)"); @@ -504,6 +535,8 @@ public final class EMail implements Serializable } catch (Exception e) { + if (throwException) + throw e; log.log(Level.SEVERE, "", e); m_sentMsg = e.getLocalizedMessage(); Env.getCtx().put(EMAIL_SEND_MSG, m_sentMsg); @@ -560,13 +593,13 @@ public final class EMail implements Serializable */ private void dumpMessage() { - if (m_msg == null) + if (m_msg == null || !log.isLoggable(Level.FINEST)) return; try { Enumeration e = m_msg.getAllHeaderLines (); while (e.hasMoreElements ()) - if (log.isLoggable(Level.FINE)) log.fine("- " + e.nextElement ()); + log.finest("- " + e.nextElement ()); } catch (MessagingException ex) {