Comment SendMail
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 10 Feb 2012 18:47:56 +0000 (18:47 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 10 Feb 2012 18:47:56 +0000 (18:47 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5044 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/mail/SendMail.java

index 3a570eefa2fb53c2c66031154aa3d378cc93195d..9354a1029f88027d57387605822af6c71a80345b 100644 (file)
@@ -26,12 +26,19 @@ import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.core.execution.tasks.SystemCall;
 
-// http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailUsage
-// http://java.sun.com/products/javamail/FAQ.html#gmail
+/** Sends a mail via JavaMail, local mail command or Google Mail. */
 public class SendMail implements Runnable {
+       // See:
+       // http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailUsage
+       // http://java.sun.com/products/javamail/FAQ.html#gmail
+
+       private final static Log log = LogFactory.getLog(SendMail.class);
+
        private String host;
        private String from;
        private String to;
@@ -54,6 +61,8 @@ public class SendMail implements Runnable {
                SystemCall mail = new SystemCall("mail");
                mail.arg("-s", subject).arg(to);
                mail.run();
+               if (log.isDebugEnabled())
+                       log.debug("Sent mail to " + to + " with OS mail command");
        }
 
        protected void sendWithJavaMail() {
@@ -76,6 +85,8 @@ public class SendMail implements Runnable {
 
                        // Send message
                        Transport.send(message);
+                       if (log.isDebugEnabled())
+                               log.debug("Sent mail to " + to + " with JavaMail");
                } catch (Exception e) {
                        throw new SlcException("Cannot send message.", e);
                }
@@ -96,7 +107,8 @@ public class SendMail implements Runnable {
                        } finally {
                                t.close();
                        }
-
+                       if (log.isDebugEnabled())
+                               log.debug("Sent mail to " + to + " with Google Mail");
                } catch (Exception e) {
                        throw new SlcException("Cannot send message.", e);
                }