details:   https://code.openbravo.com/erp/devel/pi/rev/fca1e4e42285
changeset: 33972:fca1e4e42285
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu May 17 17:22:21 2018 +0200
summary:   fixed bug 38567: can get stuck forever sending emails

  Added a fixed 10 minutes timeout for communications with smtp servers, this
  same timeout is applied to connection creation as well as reading responses
  from server. Note it is not applied to writing operations.

diffstat:

 src/org/openbravo/erpCommon/utility/poc/EmailManager.java |  7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diffs (38 lines):

diff -r 6d9d6f538641 -r fca1e4e42285 
src/org/openbravo/erpCommon/utility/poc/EmailManager.java
--- a/src/org/openbravo/erpCommon/utility/poc/EmailManager.java Thu May 17 
13:14:16 2018 +0200
+++ b/src/org/openbravo/erpCommon/utility/poc/EmailManager.java Thu May 17 
17:22:21 2018 +0200
@@ -9,7 +9,7 @@
  * either express or implied. See the License for the specific language
  * governing rights and limitations under the License. The Original Code is
  * Openbravo ERP. The Initial Developer of the Original Code is Openbravo SLU 
All
- * portions are Copyright (C) 2001-2012 Openbravo SLU All Rights Reserved.
+ * portions are Copyright (C) 2001-2018 Openbravo SLU All Rights Reserved.
  * Contributor(s): ______________________________________.
  * ***********************************************************************
  */
@@ -19,6 +19,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
@@ -44,6 +45,7 @@
 
 public class EmailManager {
   private static Logger log4j = Logger.getLogger(EmailManager.class);
+  private static final long SMTP_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
 
   public static void sendEmail(String host, boolean auth, String username, 
String password,
       String connSecurity, int port, String senderAddress, String recipientTO, 
String recipientCC,
@@ -65,6 +67,9 @@
       props.put("mail.smtp.host", host);
       props.put("mail.smtp.port", port);
 
+      props.put("mail.smtp.timeout", SMTP_TIMEOUT);
+      props.put("mail.smtp.connectiontimeout", SMTP_TIMEOUT);
+
       if (localConnSecurity != null) {
         localConnSecurity = localConnSecurity.replaceAll(", *", ",");
         String[] connSecurityArray = localConnSecurity.split(",");

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to