You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/07/02 18:22:07 UTC

svn commit: r960047 - in /jakarta/jmeter/trunk: src/core/org/apache/jmeter/resources/messages.properties src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java xdocs/usermanual/component_reference.xml

Author: sebb
Date: Fri Jul  2 16:22:06 2010
New Revision: 960047

URL: http://svn.apache.org/viewvc?rev=960047&view=rev
Log:
Allow SMTP port to be defaulted

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=960047&r1=960046&r2=960047&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Fri Jul  2 16:22:06 2010
@@ -795,7 +795,7 @@ smtp_attach_file_tooltip=Separate multip
 smtp_auth_settings=Auth settings
 smtp_bcc=Address To BCC:
 smtp_cc=Address To CC:
-smtp_default_port=(Default: 25)
+smtp_default_port=(Defaults: SMTP:25, SSL:465, StartTLS:587)
 smtp_eml=Send .eml:
 smtp_enforcestarttls=Enforce StartTLS
 smtp_enforcestarttls_tooltip=<html><b>Enforces</b> the server to use StartTLS.<br />If not selected and the SMTP-Server doesn't support StartTLS, <br />a normal SMTP-Connection will be used as fallback instead. <br /><i>Please note</i> that this checkbox creates a file in \"/tmp/\", <br />so this will cause problems under windows.</html>

Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java?rev=960047&r1=960046&r2=960047&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java (original)
+++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java Fri Jul  2 16:22:06 2010
@@ -26,7 +26,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
-import java.security.Security;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -76,7 +75,7 @@ public class SendMailCommand {
     private List<InternetAddress> receiverTo;
     private List<InternetAddress> receiverCC;
     private List<InternetAddress> receiverBCC;
-    private HashMap<String, String> headers;
+    private HashMap<String, String> headers; // Not currently set up
     private String subject = "";
 
     private boolean useAuthentication = false;
@@ -126,17 +125,16 @@ public class SendMailCommand {
 
         // set properties using JAF
         props.put("mail." + protocol + ".host", smtpServer);
-        props.put("mail." + protocol + ".port", smtpPort);
-        props.put("mail." + protocol + ".auth", Boolean
-                .toString(useAuthentication));
-        // props.put("mail.debug","true");
+        props.put("mail." + protocol + ".port", getPort());
+        props.put("mail." + protocol + ".auth", Boolean.toString(useAuthentication));
+//        props.put("mail.debug","true");
 
         if (useStartTLS) {
             props.put("mail.smtp.starttls.enable", "true");
             //props.put("mail.debug", "true");
         }
 
-        if (trustAllCerts && protocol.equalsIgnoreCase("smtps")) {
+        if (trustAllCerts && useSSL) {
             props.setProperty("mail.smtps.socketFactory.class",
                     TRUST_ALL_SOCKET_FACTORY);
             props.setProperty("mail.smtps.socketFactory.fallback", "false");
@@ -264,7 +262,7 @@ public class SendMailCommand {
         tr.sendMessage(message, message.getAllRecipients());
 
         if (synchronousMode) {
-            listener.attend();
+            listener.attend(); // listener cannot be null here
         }
 
         tr.close();
@@ -700,6 +698,26 @@ public class SendMailCommand {
     }
 
     /**
+     * Returns port to be used for SMTP-connection - returns the
+     * default port for the protocol if no port has been supplied.
+     * 
+     * @return Port to be used for SMTP-connection
+     */
+    private String getPort() {
+        String port = smtpPort.trim();
+        if (port.length() > 0) { // OK, it has been supplied
+            return port;
+        }
+        if (useSSL){
+            return "465";
+        }
+        if (useStartTLS) {
+            return "587";
+        }
+        return "25";
+    }
+
+    /**
      * Assigns the object to use a local truststore for SSL / StartTLS - to be
      * called by SmtpSampler-object
      *

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=960047&r1=960046&r2=960047&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Fri Jul  2 16:22:06 2010
@@ -1511,9 +1511,11 @@ Two alternatives to handle this verifica
 </description>
 <properties>
 <property name="Server" required="Yes">Hostname or IP address of the server. See below for use with <code>file</code> protocol.</property>
-<property name="Port" required="Yes">Port to be used to connect to the server (optional)</property>
+<property name="Port" required="No">Port to be used to connect to the server.
+Defaults are: SMTP=25, SSL=465, StartTLS=587
+</property>
 <property name="Address From" required="Yes">The from address that will appear in the e-mail</property>
-<property name="Address To" required="Yes">The destination e-mail address</property>
+<property name="Address To" required="Yes, unless CC or BCC is specified">The destination e-mail address</property>
 <property name="Address To BCC" required="No">Blind carbon copy destinations e-mail address</property>
 <property name="Address To CC" required="No">Carbon copy destinations e-mail address</property>
 <property name="Use Auth" required="">Indicates if the SMTP server requires user authentication</property>



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org