Hi,
I attach a patch that allows to configure the SMTP authentication in the property file.

I've added two new properties:
MAIL_SMTP_USER = "mail.smtp.user";
MAIL_SMTP_PWD = "mail.smtp.pwd";

This allows software thought to work without SMTP authentication (making the SMTP server open to be abused by spammers) to add transparently SMTP authentication.

Can it be a worthy enhancment?
Thanks for any feedback,
Fabio



Index: src/java/org/apache/commons/mail/Email.java
===================================================================
--- src/java/org/apache/commons/mail/Email.java (revisione 189785)
+++ src/java/org/apache/commons/mail/Email.java (copia locale)
@@ -75,6 +75,10 @@
     /** */
     public static final String MAIL_HOST = "mail.host";
     /** */
+    public static final String MAIL_SMTP_USER = "mail.smtp.user";
+    /** */
+    public static final String MAIL_SMTP_PWD = "mail.smtp.pwd";
+    /** */
     public static final String MAIL_PORT = "mail.smtp.port";
     /** */
     public static final String MAIL_SMTP_FROM = "mail.smtp.from";
@@ -350,7 +354,7 @@
             {
                 this.hostName = properties.getProperty(MAIL_HOST);
             }
-
+
             if (!StringUtils.isNotEmpty(this.hostName))
             {
                 throw new EmailException(
@@ -364,6 +368,16 @@
             if (this.authenticator != null)
             {
                 properties.setProperty(MAIL_SMTP_AUTH, "true");
+            } else {
+                // if there's not an explicit authenticator we
+                // check if there's enough info in the System properties
+                String user=properties.getProperty(MAIL_SMTP_USER);
+                String pwd =properties.getProperty(MAIL_SMTP_PWD );
+
+                if (!StringUtils.isNotEmpty(user) && 
!StringUtils.isNotEmpty(pwd)) {
+                    this.authenticator=new DefaultAuthenticator(user,pwd);
+                    properties.setProperty(MAIL_SMTP_AUTH, "true");
+                }
             }

             if (this.bounceAddress != null)

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

Reply via email to