commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1665699 - in /commons/proper/email/trunk/src: changes/changes.xml main/java/org/apache/commons/mail/Email.java main/java/org/apache/commons/mail/EmailConstants.java test/java/org/apache/commons/mail/EmailTest.java
Date Tue, 10 Mar 2015 21:12:10 GMT
Author: tn
Date: Tue Mar 10 21:12:09 2015
New Revision: 1665699

URL: http://svn.apache.org/r1665699
Log:
[EMAIL-149] Allow sending an Email if no from or bounce address is specified but a mail.from
property is set in the mail session. Thanks to Richard DiCroce.

Modified:
    commons/proper/email/trunk/src/changes/changes.xml
    commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java
    commons/proper/email/trunk/src/main/java/org/apache/commons/mail/EmailConstants.java
    commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java

Modified: commons/proper/email/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1665699&r1=1665698&r2=1665699&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Tue Mar 10 21:12:09 2015
@@ -23,6 +23,11 @@
 
   <body>
     <release version="1.4.0" date="2014-??-??">
+      <action dev="tn" type="fix" issue="EMAIL-149" date="2015-03-10" due-to="Richard
DiCroce">
+        "Email" threw an "EmailException" when trying to send the email if neither a from
+        nor bounce address was specified, although a "mail.from" property was set in the
+        mail session.
+      </action>
       <action dev="tn" type="fix" issue="EMAIL-151" date="2015-03-10" due-to="Andreas
Kohn">
         "ImageHtmlEmail" failed to embed attachments if their data source name was null.
       </action>

Modified: commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java?rev=1665699&r1=1665698&r2=1665699&view=diff
==============================================================================
--- commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java (original)
+++ commons/proper/email/trunk/src/main/java/org/apache/commons/mail/Email.java Tue Mar 10
21:12:09 2015
@@ -1328,7 +1328,8 @@ public abstract class Email
             }
             else
             {
-                if (session.getProperty(MAIL_SMTP_FROM) == null)
+                if (session.getProperty(EmailConstants.MAIL_SMTP_FROM) == null
+                        && session.getProperty(EmailConstants.MAIL_FROM) == null)
                 {
                     throw new EmailException("From address required");
                 }

Modified: commons/proper/email/trunk/src/main/java/org/apache/commons/mail/EmailConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/main/java/org/apache/commons/mail/EmailConstants.java?rev=1665699&r1=1665698&r2=1665699&view=diff
==============================================================================
--- commons/proper/email/trunk/src/main/java/org/apache/commons/mail/EmailConstants.java (original)
+++ commons/proper/email/trunk/src/main/java/org/apache/commons/mail/EmailConstants.java Tue
Mar 10 21:12:09 2015
@@ -231,6 +231,17 @@ public final class EmailConstants
      */
     public static final String MAIL_MIME_CHARSET = "mail.mime.charset";
 
+    /////////////////////////////////////////////////////////////////////////
+    // since 1.4
+    /////////////////////////////////////////////////////////////////////////
+
+    /**
+     * The from email address.
+     * @since 1.4
+     */
+    public static final String MAIL_FROM = "mail.from";
+
+
     /** Hide constructor. */
     private EmailConstants()
     {

Modified: commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java?rev=1665699&r1=1665698&r2=1665699&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java (original)
+++ commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java Tue Mar
10 21:12:09 2015
@@ -1001,6 +1001,21 @@ public class EmailTest extends AbstractE
          email = new MockEmailConcrete();
          email.setHostName(strTestMailServer);
          email.setSmtpPort(getMailServerPort());
+         email.addTo("me@home.com");
+
+         email.send();
+    }
+
+    @Test
+    public void testSendFromSetInSession() throws Exception
+    {
+         getMailServer();
+
+         email = new MockEmailConcrete();
+         email.setHostName(strTestMailServer);
+         email.setSmtpPort(getMailServerPort());
+         email.addTo("me@home.com");
+         email.getSession().getProperties().setProperty(EmailConstants.MAIL_FROM, "me@home.com");
 
          email.send();
     }



Mime
View raw message