Author: sgoeschl
Date: Mon Oct 10 02:52:59 2005
New Revision: 312593

URL: http://svn.apache.org/viewcvs?rev=312593&view=rev
Log:
+) Using official commons-email-1.0 release which now contains the patch 
required to work with this service
+) Added support for creating SMTP session without relying on commons-email.
+) Providing a send() using an explicit list of recipients. This is a mandatory 
functionality for our SMTP gateway.
+) Adding connection timeouts supported by javamail-1.3.3 but stick to 
javamail-1.3.2 for the time being

Added:
    
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailConstants.java
    
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java
Modified:
    jakarta/turbine/fulcrum/trunk/commonsemail/project.xml
    
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java
    
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java
    
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java
    jakarta/turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml
    
jakarta/turbine/fulcrum/trunk/commonsemail/src/test/org/apache/fulcrum/commonsemail/CommonsEmailServiceTest.java
    jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/changes.xml
    jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/configuration.xml

Modified: jakarta/turbine/fulcrum/trunk/commonsemail/project.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/project.xml?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- jakarta/turbine/fulcrum/trunk/commonsemail/project.xml (original)
+++ jakarta/turbine/fulcrum/trunk/commonsemail/project.xml Mon Oct 10 02:52:59 
2005
@@ -4,7 +4,7 @@
   <extend>${basedir}/../project.xml</extend>
   <id>fulcrum-commonsemail</id>
   <name>Fulcrum CommonsEmail Service</name>
-  <currentVersion>1.0.0</currentVersion>
+  <currentVersion>1.0.1-dev</currentVersion>
   
   <dependencies>
     <dependency>
@@ -17,7 +17,7 @@
     <dependency>
         <groupId>commons-email</groupId>
         <artifactId>commons-email</artifactId>
-        <version>20050601.114714</version>
+        <version>1.0</version>
         <url>http://jakarta.apache.org/commons/email.html</url>
         <properties/>
     </dependency>

Modified: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java
 (original)
+++ 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java
 Mon Oct 10 02:52:59 2005
@@ -19,6 +19,7 @@
 
 import java.util.Hashtable;
 
+import javax.mail.Address;
 import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
@@ -44,6 +45,36 @@
 public interface CommonsEmailService
 {
     /**
+     * Determines if any email for the given domain name will 
+     * be sent or silently consumed by the service without
+     * delivering it.
+     * 
+     * @param domainName the domain name
+     * @return true if the email will not be sent by the service
+     */
+    boolean isMailDoNotSend(String domainName);
+    
+    /**
+     * Factory method to create a mail session based on the domain 
configuration.
+     * 
+     * @param domainName the domain name
+     * @return a mail session
+     */
+    Session createSmtpSession(String domainName);
+
+    /**
+     * Factory method to create a mail session based on the domain 
configuration 
+     * and a user-supplied username and password. We assume that SMTP AUTH is
+     * used.
+     * 
+     * @param domainName the domain name
+     * @param username the user name used for SMTP authentication
+     * @param password the password used for SMTP authentication
+     * @return a mail session
+     */
+    Session createSmtpSession(String domainName, String username, String 
password);
+
+    /**
      * Factory method for creating a SimpleEmail with fully
      * configured mail session based on the domain configuration.
      * 
@@ -147,6 +178,22 @@
      * @throws MessagingException sending the email failed
      */
     MimeMessage send(String domainName, Session session, MimeMessage 
mimeMessage) 
+       throws MessagingException;        
+
+    /**
+     * Sends a MimeMessage using the service instead of calling 
+     * Transport.send(). This allows to overwrite the receivers
+     * of the email as an additional security measure for sending
+     * thousands of emails using real-world email addresses. 
+     * 
+     * @param domainName the sender of the email
+     * @param session the email session
+     * @param mimeMessage the email to be sent
+     * @param recipients the list of recipients
+     * @return the MimeMessage being sent
+     * @throws MessagingException sending the email failed
+     */
+    MimeMessage send(String domainName, Session session, MimeMessage 
mimeMessage, Address[] recipients) 
        throws MessagingException;        
 
     /**

Added: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailConstants.java
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailConstants.java?rev=312593&view=auto
==============================================================================
--- 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailConstants.java
 (added)
+++ 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailConstants.java
 Mon Oct 10 02:52:59 2005
@@ -0,0 +1,35 @@
+package org.apache.fulcrum.commonsemail.impl;

+

+/*

+ * Copyright 2004 Apache Software Foundation

+ * Licensed  under the  Apache License,  Version 2.0  (the "License");

+ * you may not use  this file  except in  compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed  under the  License is distributed on an "AS IS" BASIS,

+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or

+ * implied.

+ *

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+

+/**

+ * Contains all transport releated session properties for javamail-1.3.3.

+ * 

+ * @author <a href="mailto:[EMAIL PROTECTED]">Siegfried Goeschl</a>

+ */

+

+public interface CommonsEmailConstants extends CommonsEmailSmtpConstants

+{

+    /** Specifies the initial debug mode. */

+    public static final String MAIL_DEBUG = "mail.debug";

+    

+    /** Specifies the default Transport Protocol. */

+    public static final String MAIL_TRANSPORT_PROTOCOL = 
"mail.transport.protocol";

+}

+


Modified: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java
 (original)
+++ 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java
 Mon Oct 10 02:52:59 2005
@@ -72,7 +72,16 @@
 
     /** the port of the mail server */
     private int mailSmtpPort;
-
+    
+    /** socket connection timeout value in milliseconds */
+    private int mailSmtpConnectionTimeout;
+    
+       /** socket I/O timeout value in millisecond */
+    private int mailSmtpTimeout;
+    
+    /** if the message has some valid and some invalid addresses, send the 
message anyway */
+    private boolean mailSmtpSendPartial;
+    
     /** the email address of the sender */
     private String mailFromEmail;
 
@@ -154,6 +163,7 @@
      * Initialize this instance.
      * 
      * @param conf the domain configuration 
+     * @return the fully configured instance
      * @throws ConfigurationException the configuration failed
      */
     public CommonsEmailDomainEntry initialize( Configuration conf )
@@ -169,9 +179,11 @@
         this.mailCharset = conf.getChild("mailCharset").getValue(null);
         
         this.mailSmtpHost = conf.getChild("mailSmtpHost").getValue(
-            System.getProperty("mail.smtp.host")
+            System.getProperty("mail.smtp.host","localhost")
             );
         
+        // determine SMTP port either from the configuration or from the 
system properties
+        
         this.mailSmtpPort = 
conf.getChild("mailSmtpPort").getValueAsInteger(0);    
         
         if( this.mailSmtpPort == 0 )
@@ -181,6 +193,9 @@
                 );
         }
         
+        this.mailSmtpConnectionTimeout = 
conf.getChild("mailSmtpConnectionTimeout").getValueAsInteger(Integer.MAX_VALUE);
+        this.mailSmtpTimeout = 
conf.getChild("mailSmtpConnectionTimeout").getValueAsInteger(Integer.MAX_VALUE);
+        this.mailSmtpSendPartial = 
conf.getChild("mailSmtpSendPartial").getValueAsBoolean(false);
         this.mailFromEmail = conf.getChild("mailFromEmail").getValue(null);
         this.mailFromName = conf.getChild("mailFromName").getValue(null);
         this.mailReplyToEmail = 
conf.getChild("mailReplyToEmail").getValue(this.mailFromEmail);
@@ -278,7 +293,6 @@
             this.onNotSendHookConfiguration = hookConf.getChild("onNotSend");
         }
         
-        
         return this;
     }
  
@@ -292,8 +306,6 @@
         result.append(getClass().getName() + "@" + 
Integer.toHexString(hashCode()));
         
         result.append('[');
-        result.append("authPassword=" + this.getAuthPassword());        
-        result.append(',');
         result.append("authPopHost=" + this.getAuthPopHost());
         result.append(',');
         result.append("authType=" + this.getAuthType());
@@ -332,6 +344,12 @@
         result.append(',');
         result.append("mailSmtpPort=" + this.getMailSmtpPort());               
 
         result.append(',');
+        result.append("mailSmtpConnectionTimeout=" + 
this.getMailSmtpConnectionTimeout());                
+        result.append(',');
+        result.append("mailSmtpTimeout=" + this.getMailSmtpTimeout());         
       
+        result.append(',');
+        result.append("mailSmtpSendPartial=" + this.isMailSmtpSendPartial());  
              
+        result.append(',');
         result.append("overwriteBcc=" + this.getOverwriteBcc());               
 
         result.append(',');
         result.append("overwriteCc=" + this.getOverwriteCc());                
@@ -496,7 +514,31 @@
     }
     
     /**
-     * Is any type of authentication used for this domain?
+     * @return Returns the mailSmtpConnectionTimeout.
+     */
+    public int getMailSmtpConnectionTimeout()
+    {
+        return mailSmtpConnectionTimeout;
+    }
+    
+    /**
+     * @return Returns the mailSmtpTimeout.
+     */
+    public int getMailSmtpTimeout()
+    {
+        return mailSmtpTimeout;
+    }
+    
+    /**
+     * @return Returns the mailSmtpSendPartial.
+     */
+    public boolean isMailSmtpSendPartial()
+    {
+        return mailSmtpSendPartial;
+    }
+    
+    /**
+     * @return Is any type of authentication used for this domain?
      */
     public boolean hasAuthentication()
     {
@@ -511,7 +553,7 @@
     }
 
     /**
-     * Is SMTP authentication used for this domain?
+     * @return Is SMTP authentication used for this domain?
      */
     public boolean hasSmtpAuthentication()
     {
@@ -526,7 +568,7 @@
     }
 
     /**
-     * Is PopBeforeSMTP authentication used for this domain?
+     * @return Is PopBeforeSMTP authentication used for this domain?
      */
     public boolean hasPopBeforeSmtpAuthentication()
     {

Modified: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java
 (original)
+++ 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java
 Mon Oct 10 02:52:59 2005
@@ -24,6 +24,7 @@
 import java.util.Collection;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Properties;
 
 import javax.activation.DataSource;
 import javax.mail.Address;
@@ -45,6 +46,7 @@
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.mail.DefaultAuthenticator;
 import org.apache.commons.mail.Email;
 import org.apache.commons.mail.EmailAttachment;
 import org.apache.commons.mail.EmailException;
@@ -67,7 +69,8 @@
 
 public class CommonsEmailServiceImpl
     extends AbstractLogEnabled
-    implements CommonsEmailService, Contextualizable, Reconfigurable, 
Initializable, Disposable, TransportListener
+    implements CommonsEmailService, Contextualizable, Reconfigurable, 
Initializable, Disposable, 
+       TransportListener, CommonsEmailConstants
 {    
     /** the Avalon home directory */
     private File serviceHomeDir;
@@ -158,6 +161,73 @@
     /////////////////////////////////////////////////////////////////////////
     
     /**
+     * @see 
org.apache.fulcrum.commonsemail.CommonsEmailService#isMailDoNotSend(java.lang.String)
+     */
+    public boolean isMailDoNotSend(String domainName)
+    {
+        CommonsEmailDomainEntry domain = this.getDomain(domainName);
+        return domain.isMailDoNotSend();
+    }
+    
+    /**
+     * @see 
org.apache.fulcrum.commonsemail.CommonsEmailService#createSmtpSession(java.lang.String)
+     */
+    public Session createSmtpSession(String domainName)
+    {
+        CommonsEmailDomainEntry domain = this.getDomain(domainName);
+
+        return this.createSmtpSession(
+            domainName,
+            domain.getAuthUsername(),
+            domain.getAuthPassword()
+            );
+    }
+
+    /**
+     * @see 
org.apache.fulcrum.commonsemail.CommonsEmailService#createSmtpSession(java.lang.String,
 java.lang.String, java.lang.String)
+     */
+    public Session createSmtpSession(String domainName, String username,
+        String password)
+    {
+        Session result = null;
+        CommonsEmailDomainEntry domain = this.getDomain(domainName);
+        Properties properties = new Properties(System.getProperties());
+        DefaultAuthenticator authenticator = null;
+
+        properties.setProperty(MAIL_DEBUG, 
Boolean.toString(domain.isMailDebug()));
+        properties.setProperty(MAIL_TRANSPORT_PROTOCOL, "smtp");
+        properties.setProperty(MAIL_SMTP_HOST, domain.getMailSmtpHost());
+        properties.setProperty(MAIL_SMTP_PORT, 
Integer.toString(domain.getMailSmtpPort()));
+        properties.setProperty(MAIL_SMTP_CONNECTIONTIMEOUT, 
Integer.toString(domain.getMailSmtpConnectionTimeout()));
+        properties.setProperty(MAIL_SMTP_TIMEOUT, 
Integer.toString(domain.getMailSmtpTimeout()));
+        properties.setProperty(MAIL_SMTP_SENTPARTIAL, 
Boolean.toString(domain.isMailSmtpSendPartial()));
+        
+        properties.setProperty(MAIL_SMTP_FROM,domain.getMailBounceAddress());
+        
+        // if SMTP AUTH is enabled create a default authenticator 
+        
+        if( domain.hasSmtpAuthentication() )
+        {
+            properties.setProperty(MAIL_SMTP_AUTH, "true");
+
+            authenticator = new DefaultAuthenticator(
+                username,
+                password
+                );
+        }
+
+        if( domain.hasSmtpAuthentication() )
+        {
+            result = Session.getInstance(properties, authenticator);
+        }
+        else
+        {
+            result = Session.getInstance(properties);
+        }
+        
+        return result;
+    }
+    /**
      * @see 
org.apache.fulcrum.commonsemail.CommonsEmailService#createHtmlEmail(java.lang.String)
      */
     public HtmlEmail createHtmlEmail(String domainName) throws EmailException
@@ -222,7 +292,8 @@
             this.send(
                 domain, 
                 email.getMailSession(),
-                mimeMessage
+                mimeMessage,
+                mimeMessage.getAllRecipients()
                 );
                 
             return mimeMessage;
@@ -271,11 +342,40 @@
         this.send(
             domain, 
             session,
-            mimeMessage
+            mimeMessage,
+            mimeMessage.getAllRecipients()
             );
         
-        return result;         
+        return result;            
+    }
+    
+    /**
+     * @see 
org.apache.fulcrum.commonsemail.CommonsEmailService#send(java.lang.String, 
javax.mail.Session, javax.mail.internet.MimeMessage, javax.mail.Address[])
+     */
+    public MimeMessage send(String domainName, Session session,
+        MimeMessage mimeMessage, Address [] recipients)
+        throws MessagingException
+    {
+        MimeMessage result = null;
+        
+        // get the configuration of this domain
+        
+        CommonsEmailDomainEntry domain = this.getDomain(domainName);
         
+        //     update the MimeMessage based on the domain configuration
+        
+        result = this.updateMimeMessage(domain, mimeMessage);
+        
+        // send the MimeMessage 
+        
+        this.send(
+            domain, 
+            session,
+            mimeMessage,
+            recipients
+            );
+        
+        return result;            
     }
     
     /**
@@ -288,7 +388,13 @@
          
          // determine the domain name
          
-         String domainName = ((InternetAddress) 
(mimeMessage.getFrom()[0])).getAddress();
+         if( ( mimeMessage.getFrom() == null ) || ( 
mimeMessage.getFrom().length == 0 ) )
+         {
+             throw new MessagingException("No from address defined - unable to 
determine a domain configuration");
+         }
+         
+         InternetAddress fromAddress = (InternetAddress) 
mimeMessage.getFrom()[0];
+         String domainName = fromAddress.getAddress();
          
          // get the configuration of this domain
          
@@ -303,7 +409,8 @@
          this.send(
              domain, 
              session,
-             mimeMessage
+             mimeMessage,
+             mimeMessage.getAllRecipients()
              );
          
          return result;         
@@ -493,11 +600,14 @@
      * Sends a MimeMessage. We use a Transport instance to register
      * a transport listener to track invalid email addresses.
      * 
+     * @param domain the domain configuration
+     * @param sesssion the mail sessoin
      * @param mimeMessage the MimeMessage to be sent
+     * @param recipients the list of recipients
      * @throws MessagingException sending the MimeMessage failed
      */
     private void send(
-        CommonsEmailDomainEntry domain, Session session, MimeMessage 
mimeMessage) 
+        CommonsEmailDomainEntry domain, Session session, MimeMessage 
mimeMessage, Address[] recipients) 
        throws MessagingException
     {        
         if( this.getLogger().isDebugEnabled() )
@@ -524,8 +634,17 @@
                 Transport transport = session.getTransport("smtp");
                 
                 transport.addTransportListener(this);
-                transport.connect();           
-                transport.sendMessage(mimeMessage, 
mimeMessage.getAllRecipients());
+                transport.connect();         
+                
+                if( (recipients == null) || (recipients.length == 0) )
+                {
+                    transport.sendMessage(mimeMessage, 
mimeMessage.getAllRecipients());
+                }
+                else
+                {
+                    transport.sendMessage(mimeMessage, recipients);
+                }
+                
                 transport.close();                
                 
                 long endTime = System.currentTimeMillis();

Added: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java?rev=312593&view=auto
==============================================================================
--- 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java
 (added)
+++ 
jakarta/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java
 Mon Oct 10 02:52:59 2005
@@ -0,0 +1,141 @@
+package org.apache.fulcrum.commonsemail.impl;

+

+/*

+ * Copyright 2004 Apache Software Foundation

+ * Licensed  under the  Apache License,  Version 2.0  (the "License");

+ * you may not use  this file  except in  compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed  under the  License is distributed on an "AS IS" BASIS,

+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or

+ * implied.

+ *

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+

+/**

+ * Contains all SMTP releated session properties for javamail-1.3.3.

+ * 

+ * @author <a href="mailto:[EMAIL PROTECTED]">Siegfried Goeschl</a>

+ */

+

+public interface CommonsEmailSmtpConstants

+{

+    /** Default user name for SMTP */

+    public static final String MAIL_SMTP_USER = "mail.smtp.user";

+

+    /** The SMTP server to connect to */

+    public static final String MAIL_SMTP_HOST = "mail.smtp.host";

+

+    /**        

+     * The SMTP server port to connect to, if the connect() method 

+     * doesn't explicitly specify one. Defaults to 25 

+     */

+    public static final String MAIL_SMTP_PORT = "mail.smtp.port";

+

+    /** 

+     * Socket connection timeout value in milliseconds. Default is 

+     * infinite timeout. 

+     */

+    public static final String MAIL_SMTP_CONNECTIONTIMEOUT = 
"mail.smtp.connectiontimeout";

+

+    /** 

+     * Socket I/O timeout value in milliseconds. Default is infinite timeout. 

+     */

+    public static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout";

+    

+    /** Email address to use for SMTP MAIL command */

+    public static final String MAIL_SMTP_FROM = "mail.smtp.from";

+

+    /** Local host name used in the SMTP HELO or EHLO command */

+    public static final String MAIL_SMTP_LOCALHOST = "mail.smtp.localhost";

+

+    /** Local address (host name) to bind to when creating the SMTP socket */

+    public static final String MAIL_SMTP_LOCALADDRESS = 
"mail.smtp.localaddress";

+

+    /** Local port number to bind to when creating the SMTP socket */

+    public static final String MAIL_SMTP_LOCALPORT = "mail.smtp.localport";

+

+    /** If false, do not attempt to sign on with the EHLO command */

+    public static final String MAIL_SMTP_EHLO = "mail.smtp.ehlo";

+

+    /** If true, attempt to authenticate the user using the AUTH command */

+    public static final String MAIL_SMTP_AUTH = "mail.smtp.auth";

+

+    /**  The submitter to use in the AUTH tag in the MAIL FROM command */

+    public static final String MAIL_SMTP_SUBMITTER = "mail.smtp.submitter";

+

+    /** 

+     * The NOTIFY option to the RCPT command. Either NEVER, or some 
combination of 

+     * SUCCESS, FAILURE, and DELAY (separated by commas). 

+     */

+    public static final String MAIL_SMTP_DSN_NOTIFY = "mail.smtp.dsn.notify";

+

+    /** The RET option to the MAIL command. Either FULL or HDRS. */

+    public static final String MAIL_SMTP_DSN_RET = "mail.smtp.dsn.ret";

+

+    /**

+     * If set to true, and the server supports the 8BITMIME extension, 

+     * text parts of messages that use the "quoted-printable" or 

+     * "base64" encodings are converted to use "8bit" encoding if they 

+     * follow the RFC2045 rules for 8bit text.*/

+    public static final String MAIL_SMTP_ALLOW8BITMIME = 
"mail.smtp.allow8bitmime";

+

+    /** 

+     * If set to true, and a message has some valid and some invalid 

+     * addresses, send the message anyway, reporting the partial failure

+     * with a SendFailedException. If set to false (the default), the 

+     * message is not sent to any of the recipients if there is an 

+     * invalid recipient address. */

+    public static final String MAIL_SMTP_SENTPARTIAL = "mail.smtp.sendpartial";

+

+    /** The realm to use with DIGEST-MD5 authentication. */

+    public static final String MAIL_SMTP_SASL_REALM = "mail.smtp.sasl.realm";

+

+    /** If set to true, causes the transport to wait for the response to the 
QUIT command */

+    public static final String MAIL_SMTP_QUITWAIT = "mail.smtp.quitwait";

+

+    /**

+     * If set to true, causes the transport to include an 
SMTPAddressSucceededException 

+     * for each address that is successful. Note also that this will cause 

+     * a SendFailedException to be thrown from the sendMessage method of 

+     * SMTPTransport even if all addresses were correct and the message 

+     * was sent successfully.

+     */

+    public static final String MAIL_SMTP_REPORTSUCCESS = 
"mail.smtp.reportsuccess";

+

+    /** 

+     * If set, specifies the name of a class that implements the 

+     * javax.net.SocketFactory interface. This class will be used to create 

+     * SMTP sockets. 

+     */

+    public static final String MAIL_SMTP_SOCKETFACTORY_CLASS = 
"mail.smtp.socketFactory.class";

+

+    /** 

+     *  If set to true, failure to create a socket using the specified

+     *  socket factory class will cause the socket to be created 

+     *  using the java.net.Socket class. Defaults to true 

+     */

+    public static final String MAIL_SMTP_SOCKETFACTORY_FALLBACK = 
"mail.smtp.socketFactory.fallback";

+

+    /** 

+     *  Specifies the port to connect to when using the specified socket 
factory. 

+     * If not set, the default port will be used.

+     */

+    public static final String MAIL_SMTP_SOCKETFACTORY_PORT = 
"mail.smtp.socketFactory.port";

+

+    /**

+     * Extension string to append to the MAIL command. The extension string 

+     * can be used to specify standard SMTP service extensions as well 

+     * as vendor-specific extensions. Typically the application should use 

+     * the SMTPTransport method supportsExtension to verify that the server 

+     * supports the desired service extension. See RFC 1869 and other RFCs 

+     * that define specific extensions.  

+     * */

+    public static final String MAIL_SMTP_MAILEXTENSION = 
"mail.smtp.mailextension";

+}
\ No newline at end of file

Modified: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- jakarta/turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml 
(original)
+++ jakarta/turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml 
Mon Oct 10 02:52:59 2005
@@ -2,15 +2,18 @@
 
 <componentConfig>
 
-  <!-- 
+  <!--
     CommonsEmailService
-    
+
     defaultDomain := the name of the default domain if no match was found
     domains\domain := a single domain configuration
     domains\domain\domainName := the name of the domain (mandatory)
-    domains\domain\domainMatch := the match field of the domain (mandatory)
+    domains\domain\domainMatch := the match field of the domain (optinonal)
     domains\domain\mailSmtpHost := the SMTP server (optional)
     domains\domain\mailSmtpPort := the SMTP port (optional)
+    domains\domain\mailSmtpConnectionTimeout := socket connection timeout 
value in milliseconds
+    domains\domain\mailSmtpTimeout := socket I/O timeout value in milliseconds
+    domains\domain\mailSmtpSendPartial := send the email to the recipients 
even if one address is rejected
     domains\domain\mailFromEmail := the sender address of the email (optional)
     domains\domain\mailFromName := the sender name of the email (optional)
     domains\domain\bounceAddress := the bounce address if the email can't be 
delivered (optional)
@@ -25,7 +28,7 @@
     domains\domain\headers\property := the single email header
     domains\domain\overwrites\mailToEmail := overwrite the TO recipients
     domains\domain\overwrites\mailCcEmail := overwrite the CC recipients
-    domains\domain\overwrites\mailBccEmail := overwrite the BCC recipients    
+    domains\domain\overwrites\mailBccEmail := overwrite the BCC recipients
     [EMAIL PROTECTED] := is the 'onSuccess' application hook enabled
     domains\domain\hooks\onSuccess\directory := the directory to store the 
message
     [EMAIL PROTECTED] := is the 'onFailure' application hook enabled
@@ -33,7 +36,7 @@
     [EMAIL PROTECTED] := is the 'onNotSend' application hook enabled
     domains\domain\hooks\onNotSend\directory := the directory to store the 
message
   -->
-    
+
   <CommonsEmailService>
     <defaultDomain>test</defaultDomain>
     <domains>
@@ -42,6 +45,9 @@
         <domainMatch>test</domainMatch>
         <mailSmtpHost>localhost</mailSmtpHost>
         <mailSmtpPort>6025</mailSmtpPort>
+        <mailSmtpConnectionTimeout>60000</mailSmtpConnectionTimeout>
+        <mailSmtpTimeout>60000</mailSmtpTimeout>
+        <mailSmtpSendPartial>true</mailSmtpSendPartial>
         <mailFromEmail>[EMAIL PROTECTED]</mailFromEmail>
         <mailFromName>E-Billing Test</mailFromName>
         <mailReplyToEmail>[EMAIL PROTECTED]</mailReplyToEmail>
@@ -56,15 +62,15 @@
           <password>demo</password>
         </authentication>
         <headers>
-          <property name="X-Test-Domain">test</property>        
-          <property name="X-Mailer">Sendmail</property>        
-          <property name="X-Priority">1</property>        
-          <property name="Disposition-Notification-To">[EMAIL 
PROTECTED]</property>        
+          <property name="X-Test-Domain">test</property>
+          <property name="X-Mailer">Sendmail</property>
+          <property name="X-Priority">1</property>
+          <property name="Disposition-Notification-To">[EMAIL 
PROTECTED]</property>
         </headers>
         <overwrites>
           <mailToEmail>[EMAIL PROTECTED]</mailToEmail>
           <mailCcEmail></mailCcEmail>
-          <mailBccEmail></mailBccEmail>        
+          <mailBccEmail></mailBccEmail>
         </overwrites>
         <hooks>
           <onSuccess enabled="true">
@@ -76,7 +82,7 @@
           <onNotSend enabled="true">
             <directory>./temp/archive/broken/eml</directory>
           </onNotSend>
-        </hooks>        
+        </hooks>
       </domain>
       <domain>
         <domainName>it20one.at</domainName>
@@ -88,7 +94,7 @@
           <username>demo</username>
           <password>demo</password>
         </authentication>
-      </domain>      
+      </domain>
     </domains>
   </CommonsEmailService>
 

Modified: 
jakarta/turbine/fulcrum/trunk/commonsemail/src/test/org/apache/fulcrum/commonsemail/CommonsEmailServiceTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/src/test/org/apache/fulcrum/commonsemail/CommonsEmailServiceTest.java?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- 
jakarta/turbine/fulcrum/trunk/commonsemail/src/test/org/apache/fulcrum/commonsemail/CommonsEmailServiceTest.java
 (original)
+++ 
jakarta/turbine/fulcrum/trunk/commonsemail/src/test/org/apache/fulcrum/commonsemail/CommonsEmailServiceTest.java
 Mon Oct 10 02:52:59 2005
@@ -10,8 +10,14 @@
 import java.util.Hashtable;
 import java.util.Vector;
 
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
 import org.apache.commons.mail.Email;
 import org.apache.commons.mail.EmailAttachment;
 import org.apache.commons.mail.EmailException;
@@ -20,8 +26,9 @@
 import org.apache.commons.mail.SimpleEmail;
 import org.apache.fulcrum.testcontainer.BaseUnitTest;
 
+
 /**
- * PBEServiceTest
+ * CommonsEmailServiceTest
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Siegfried Goeschl</a>
  */
@@ -45,7 +52,10 @@
     /** the generated MimeMessage */
     private MimeMessage result;
     
+    /** default plain text content */
     private static final String PLAIN_CONTENT = "Hello World";
+    
+    /** default HTML text content */
     private static final String HTML_CONTENT = "<h1>Hello World</h1>";
 
     /**
@@ -81,7 +91,7 @@
         }
     }
     
-    /* (non-Javadoc)
+    /**
      * @see junit.framework.TestCase#tearDown()
      */
     protected void tearDown()
@@ -98,17 +108,37 @@
             }
             catch (Exception e)
             {
-                // TODO Auto-generated catch block
                 e.printStackTrace();
                 throw new RuntimeException(e.getMessage());
             }            
         }
-        // TODO Auto-generated method stub
+        
         super.tearDown();
     }
     
     /**
-     * @return the PDF service to be used
+     * Add all of our test suites
+     */
+    public static Test suite()
+    {
+        TestSuite suite= new TestSuite();
+        
+        suite.addTest( new CommonsEmailServiceTest("testDefaultDomain") );     
 
+        suite.addTest( new CommonsEmailServiceTest("testDerivedDomain") );     
 
+        suite.addTest( new CommonsEmailServiceTest("testHtmlEmail") );      
+        suite.addTest( new 
CommonsEmailServiceTest("testHtmlEmailWithHashtable") );      
+        suite.addTest( new CommonsEmailServiceTest("testMultiPartEmail") );    
  
+        suite.addTest( new 
CommonsEmailServiceTest("testSendEmailToUnknownServer") );      
+        suite.addTest( new CommonsEmailServiceTest("testSendMimeMessage") );   
   
+        suite.addTest( new CommonsEmailServiceTest("testSimpleEmail") );      
+        suite.addTest( new 
CommonsEmailServiceTest("testSimpleEmailWithHashtable") );      
+        suite.addTest( new 
CommonsEmailServiceTest("testCreateMimeMessageWithSession") );      
+        
+        return suite;
+    }
+
+    /**
+     * @return the CommonsEmailService service to be used
      */
     protected CommonsEmailService getService()
     {
@@ -116,7 +146,7 @@
     }
     
     /**
-     * @return Returns the subject.
+     * @return Returns the mail subject.
      */
     protected String getSubject()
     {
@@ -124,7 +154,7 @@
     }
         
     /**
-     * @return Returns the domain.
+     * @return Returns the domain name.
      */
     protected String getDomain()
     {
@@ -147,6 +177,9 @@
         return mailFrom;
     }
     
+    /**
+     * @return a preconfigured attachment
+     */
     protected EmailAttachment getEmailAttachment()
     {
         EmailAttachment attachment = new EmailAttachment();
@@ -207,7 +240,7 @@
     }           
     
     /**
-     * Use an undefined domain therefore reverting to the default domin.
+     * Use an undefined domain therefore reverting to the default domain.
      * 
      * @throws Exception
      */
@@ -240,7 +273,7 @@
     }
     
     /**
-     * Create an email using a Hashtable as input.
+     * Create a HTML email using a Hashtable as input.
      * 
      * @throws Exception
      */
@@ -310,8 +343,12 @@
         
         try
         {
-            this.result = this.getService().send(email);  
-            // fail();
+            this.result = this.getService().send(email);
+            
+            if( 
this.getService().isMailDoNotSend(email.getFromAddress().getAddress()) == false 
)
+            {
+                fail();
+            }
         }
         catch( EmailException e )
         {
@@ -319,6 +356,26 @@
         }
     }
     
+    /**
+     * Create a mail session and simple MimeMessage and sent it 
+     * @throws Exception the test failed
+     */
+    public void testCreateMimeMessageWithSession() throws Exception
+    {
+        MimeMessage mimeMessage = null;
+        Session session = 
this.getService().createSmtpSession("test","foo","bar");
+        
+        mimeMessage = new MimeMessage(session);
+        mimeMessage.setFrom(new InternetAddress(this.mailFrom));
+        mimeMessage.setSubject(this.getSubject());
+        mimeMessage.setText(PLAIN_CONTENT);
+        mimeMessage.addRecipient(Message.RecipientType.TO, new 
InternetAddress(this.mailTo));
+
+        this. result = this.getService().send(
+            session,
+            mimeMessage
+            );
+    }
     /**
      * Use commons-email to build a MimeMessage and send it directly
      * 

Modified: jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/changes.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/changes.xml?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/changes.xml (original)
+++ jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/changes.xml Mon Oct 10 
02:52:59 2005
@@ -1,16 +1,34 @@
 <?xml version="1.0"?>
 <document>
   <properties>
-    <title>IT20one PDF Service</title>
+    <title>Fulcrum CommonsEmail Service</title>
     <author email="[EMAIL PROTECTED]">Siegfried Goeschl</author>
   </properties>
 
   <body>
+    <release version="1.0.0-dev" date="as in SVN">
+     <action dev="sgoeschl" type="update">
+               Using official commons-email-1.0 release which now contains
+               the patch required to work with this service
+      </action>
+     <action dev="sgoeschl" type="add">
+        Added support for creating SMTP session without relying on
+        commons-email.
+      </action>
+     <action dev="sgoeschl" type="add">
+        Providing a send() using an explicit list of recipients. This is
+        a mandatory functionality for our SMTP gateway.
+      </action>
+     <action dev="sgoeschl" type="add">
+        Adding connection timeouts supported by javamail-1.3.3 but stick
+        to javamail-1.3.2 for the time being
+      </action>
+    </release>
     <release version="1.0.0" date="as in CVS">
      <action dev="sgoeschl" type="add">
         Initial import
-      </action>        
-    </release>    
+      </action>
+    </release>
   </body>
 </document>
 

Modified: jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/configuration.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/configuration.xml?rev=312593&r1=312592&r2=312593&view=diff
==============================================================================
--- jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/configuration.xml 
(original)
+++ jakarta/turbine/fulcrum/trunk/commonsemail/xdocs/configuration.xml Mon Oct 
10 02:52:59 2005
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <document>
   <properties>
-    <title>IT20one PDF Service</title>
+    <title>Fulcrum CommonsEmail Service</title>
     <author email="[EMAIL PROTECTED]">Siegfried Goeschl</author>
   </properties>
   <body>
@@ -15,7 +15,7 @@
     
default-class="org.apache.fulcrum.commonsemail.impl.CommonsEmailServiceImpl"
     early-init="true"
     description="Simplifies the usage of commons-email"
-  />        
+  />
 
           ]]></source>
       </subsection>
@@ -33,7 +33,7 @@
             <td>String</td>
             <td>[0|1]</td>
             <td>
-              The default domain to use if the caller-supplied 
+              The default domain to use if the caller-supplied
               domain name was not found
             </td>
           </tr>
@@ -66,7 +66,7 @@
             <td>String</td>
             <td>[0|1]</td>
             <td>
-              This field is used to match a given argument to 
+              This field is used to match a given argument to
               a domain. If no value is supplied than the
               'domainName' is used
             </td>
@@ -90,6 +90,24 @@
             </td>
           </tr>
           <tr>
+            <td>domains\domain\mailSmtpConnectionTimeout</td>
+            <td>Integer</td>
+            <td>[0|1]</td>
+            <td>
+              The socket connection timeout value in milliseconds. This 
settings
+              is only applicable for javamail-1.3.3 or higer.
+            </td>
+          </tr>
+          <tr>
+            <td>domains\domain\mailSmtpTimeout</td>
+            <td>Integer</td>
+            <td>[0|1]</td>
+            <td>
+              The socket I/O timeout value in milliseconds. This settings
+              is only applicable for javamail-1.3.3 or higer.
+            </td>
+          </tr>
+          <tr>
             <td>domains\domain\mailFromEmail</td>
             <td>String</td>
             <td>[0|1]</td>
@@ -136,7 +154,7 @@
             <td>Boolean</td>
             <td>[0|1]</td>
             <td>
-              Setting the 'mail.debug' property for the underlying mail 
session. 
+              Setting the 'mail.debug' property for the underlying mail 
session.
               If it is not set the default value 'false' is used.
             </td>
           </tr>
@@ -154,7 +172,7 @@
             <td>Boolean</td>
             <td>[0|1]</td>
             <td>
-              Skip sending of the MimeMessage? 
+              Skip sending of the MimeMessage?
             </td>
           </tr>
           <tr>
@@ -254,7 +272,7 @@
             <td>
               Contains the enforced BCC address
             </td>
-          </tr>          
+          </tr>
           <tr>
             <td>domains\domain\overwrites\mailBccEmail</td>
             <td>String</td>
@@ -262,7 +280,7 @@
             <td>
               Contains the enforced BCC address
             </td>
-          </tr>          
+          </tr>
           <tr>
             <td>domains\domain\hooks</td>
             <td>Complex</td>
@@ -270,7 +288,7 @@
             <td>
               Contains the configuration for the application hooks
             </td>
-          </tr>          
+          </tr>
           <tr>
             <td>[EMAIL PROTECTED]</td>
             <td>Boolean</td>
@@ -278,7 +296,7 @@
             <td>
               Is the hook for a sucscessfully send email enabled?
             </td>
-          </tr>                    
+          </tr>
           <tr>
             <td>[EMAIL PROTECTED]</td>
             <td>Boolean</td>
@@ -286,7 +304,7 @@
             <td>
               Is the hook for an undeliverd email enabled?
             </td>
-          </tr>                    
+          </tr>
           <tr>
             <td>[EMAIL PROTECTED]</td>
             <td>Boolean</td>
@@ -294,7 +312,7 @@
             <td>
               Is the hook for an unsent email enabled?
             </td>
-          </tr>                    
+          </tr>
         </table>
       </subsection>
 
@@ -323,16 +341,16 @@
   </CommonsEmailService>
         ]]></source>
       </subsection>
-      
+
       <subsection name="Component Configuration Example 2">
         <p>
           This is a full blown example. We define a domain 'test'
           using the SMTP server on localhost:6025 using SMTP
           auhtentication. We also define the 'from' and 'replyTo'
           since it can be overwritten by the application. Furthermore
-          all mail recipients are overwritten to ensure that the 
+          all mail recipients are overwritten to ensure that the
           emails are delivered to a test account.
-        </p>      
+        </p>
         <source><![CDATA[
   <CommonsEmailService>
     <defaultDomain>test</defaultDomain>
@@ -356,9 +374,9 @@
           <password>demo</password>
         </authentication>
         <headers>
-          <property name="X-Mailer">Sendmail</property>        
-          <property name="X-Priority">1</property>        
-          <property name="Disposition-Notification-To">[EMAIL 
PROTECTED]</property>        
+          <property name="X-Mailer">Sendmail</property>
+          <property name="X-Priority">1</property>
+          <property name="Disposition-Notification-To">[EMAIL 
PROTECTED]</property>
         </headers>
         <overwrites>
           <mailToEmail>[EMAIL PROTECTED]</mailToEmail>
@@ -370,7 +388,7 @@
   </CommonsEmailService>
         ]]></source>
       </subsection>
-      
+
     </section>
   </body>
 </document>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to