[jbpm-commits] JBoss JBPM SVN: r2988 - jbpm3/trunk/modules/core/src/main/java/org/jbpm/mail.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 19 02:58:56 EST 2008


Author: thomas.diesler at jboss.com
Date: 2008-11-19 02:58:56 -0500 (Wed, 19 Nov 2008)
New Revision: 2988

Modified:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/mail/Mail.java
Log:
Retry sendMail with new Session

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/mail/Mail.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/mail/Mail.java	2008-11-18 18:47:41 UTC (rev 2987)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/mail/Mail.java	2008-11-19 07:58:56 UTC (rev 2988)
@@ -189,56 +189,25 @@
       log.debug("skipping mail because there are no recipients");
       return;
     }
-    log.debug("sending email to '" + recipients + "' " + (bccRecipients != null ? "and in bcc to '" + bccRecipients + "' " : "") + "about '" + subject + "'");
-    Session session = Session.getDefaultInstance(mailServerProperties, null);
-    MimeMessage message = new MimeMessage(session);
+
     try
     {
-      if (fromAddress != null)
-      {
-        message.setFrom(new InternetAddress(fromAddress));
-      }
-      Iterator iter = recipients.iterator();
-      while (iter.hasNext())
-      {
-        InternetAddress recipient = new InternetAddress((String)iter.next());
-        message.addRecipient(Message.RecipientType.TO, recipient);
-      }
-      if (bccRecipients != null)
-      {
-        iter = bccRecipients.iterator();
-        while (iter.hasNext())
-        {
-          InternetAddress recipient = new InternetAddress((String)iter.next());
-          message.addRecipient(Message.RecipientType.BCC, recipient);
-        }
-      }
-      if (subject != null)
-      {
-        message.setSubject(subject);
-      }
-      if (text != null)
-      {
-        message.setText(text);
-      }
-      message.setSentDate(new Date());
-
       int retries = 5;
       while (0 < retries)
       {
         retries--;
         try
         {
-          Transport.send(message);
+          sendMailInternal(mailServerProperties, fromAddress, recipients, bccRecipients, subject, text);
           break;
         }
         catch (MessagingException msgex)
         {
-          Thread.sleep(500);
-          if (0 < retries)
-            log.error("Cannot send mail, now retrying: " + msgex);
-          else
+          if (retries == 0)
             throw msgex;
+
+          log.error("Cannot send mail, now retrying: " + msgex);
+          Thread.sleep(1000);
         }
       }
     }
@@ -248,6 +217,44 @@
     }
   }
 
+  private static void sendMailInternal(Properties mailServerProperties, String fromAddress, List recipients, List bccRecipients, String subject, String text)
+      throws Exception
+  {
+    log.debug("sending email to '" + recipients + "' " + (bccRecipients != null ? "and in bcc to '" + bccRecipients + "' " : "") + "about '" + subject + "'");
+    Session session = Session.getDefaultInstance(mailServerProperties, null);
+    MimeMessage message = new MimeMessage(session);
+    if (fromAddress != null)
+    {
+      message.setFrom(new InternetAddress(fromAddress));
+    }
+    Iterator iter = recipients.iterator();
+    while (iter.hasNext())
+    {
+      InternetAddress recipient = new InternetAddress((String)iter.next());
+      message.addRecipient(Message.RecipientType.TO, recipient);
+    }
+    if (bccRecipients != null)
+    {
+      iter = bccRecipients.iterator();
+      while (iter.hasNext())
+      {
+        InternetAddress recipient = new InternetAddress((String)iter.next());
+        message.addRecipient(Message.RecipientType.BCC, recipient);
+      }
+    }
+    if (subject != null)
+    {
+      message.setSubject(subject);
+    }
+    if (text != null)
+    {
+      message.setText(text);
+    }
+    message.setSentDate(new Date());
+
+    Transport.send(message);
+  }
+
   protected List tokenize(String text)
   {
     if (text == null)




More information about the jbpm-commits mailing list