]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/mail/SendMail.java
SLC Unit
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / mail / SendMail.java
index 3a570eefa2fb53c2c66031154aa3d378cc93195d..d2e2780ffba45d9715d17ff797f4e43271446444 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.argeo.slc.mail;
 
 import java.util.HashMap;
@@ -26,12 +25,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 +60,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 +84,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 +106,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);
                }