[cvs] expresso commit by fgalli: - EMailSender now accepts non-standard port

JCorporate Ltd jcorp at jcorporate.com
Thu Jun 30 15:12:06 UTC 2005


Log Message:
-----------
 - EMailSender now accepts non-standard port via the MAILPort setup value. 
 - Given highlight to the new SMTP header functions that didn't make it to the changelog.
 - Added appropriate messages bundle entries for IT and EN locales
 - Usage of StringUtil.EMPTY_STRING in EMailSender class.

Modified Files:
--------------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core:
        MessagesBundle_it.properties
        ExpressoSchema.java
        MessagesBundle_en.properties
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc:
        EMailSender.java
    expresso/expresso-web/expresso/doc:
        ChangeLog.xml

Revision Data
-------------
Index: MessagesBundle_it.properties
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_it.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_it.properties -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_it.properties -u -r1.5 -r1.6
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_it.properties
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_it.properties
@@ -1,10 +1,11 @@
-Web_Document_Root_Director = Web Document Root Directory on Server
+Web_Document_Root_Director = Cartella root dei documenti sul Server
 Web_Server_Host_Name = Nome dell\'Host su cui gira Web Server
 Filename_for_Server_HTML_L = Nome del file per il Log HTML Server
 Level_of_detail_in_Log = Livello di dettaglio dei Log (0=min, 9=max)
 Value_for_From_field_in_Ev = Valore per il campo di Form per E-Mail da Eventi
 Password_for_sending_e-mai = Password per l\'invio di E-Mail (se necessario)
 SMTP_Server_Name_for_sendi = Nome dello SMTP Server per l\'invio di E-Mail
+SMTP_Server_Port_for_sendi=Porta del server SMTP per invio di E-Mail
 User_Name_for_sending_e-ma=User Name per l'invio di e-mail (se necessario)
 testimonial=Testimonial
 otherProjects=Altri Progetti
Index: MessagesBundle_en.properties
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_en.properties,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_en.properties -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_en.properties -u -r1.14 -r1.15
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_en.properties
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/MessagesBundle_en.properties
@@ -5,6 +5,7 @@
 Value_for_From_field_in_Ev = Value for From field in Event E-Mails
 Password_for_sending_e-mai = Password for sending e-mail (if required)
 SMTP_Server_Name_for_sendi = SMTP Server Name for sending E-Mails
+SMTP_Server_Port_for_sendi=SMTP Server Port for sending E-Mails
 User_Name_for_sending_e-ma=User Name for sending e-mail (if required)
 #Phone
 phone=Phone
Index: ExpressoSchema.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/ExpressoSchema.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/ExpressoSchema.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/ExpressoSchema.java -u -r1.58 -r1.59
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/ExpressoSchema.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/ExpressoSchema.java
@@ -352,6 +352,9 @@
         addSetup("MAILServer",
                 getString("SMTP_Server_Name_for_sendi"),
                 getSetupDefault("MAILServer", ""));
+        addSetup("MAILPort",
+                getString("SMTP_Server_Port_for_sendi"),
+                getSetupDefault("MAILPort", "25"));
         addSetup("MAILUserName",
                 getString("User_Name_for_sending_e-ma"),
                 getSetupDefault("MAILUserName", ""));
Index: EMailSender.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java -u -r1.25 -r1.26
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java
@@ -118,6 +118,7 @@
     protected String personal = null;
     protected String host = null;
     protected String user = null;
+	protected String port = null;
     protected String password = null;
     protected String subject = null;
     protected String text = null;
@@ -367,7 +368,7 @@
         String myHost = StringUtil.notNull(host);
 
         try {
-            if (myHost.equals("")) {
+            if (myHost.equals(StringUtil.EMPTY_STRING)) {
                 myHost = Setup.getValueRequired(getDataContext(), "MAILServer");
             }
         } catch (DBException dex) {
@@ -383,6 +384,35 @@
         return myHost;
     } /* getSMTPHost() */
 
+    /**
+     * This method returns the name of the SMTP port to use to send email.
+     * First it returns the value contained in an instance variable.  If null,
+     * the value is retrieved from the setting of the MAILPort Setup parameter.
+     *
+     * @return the SMTP server port
+     * @throws Exception If MAILPort parameter is not provided in Setup
+     */
+    private String getSMTPPort()
+            throws Exception {
+        String thisMethod = thisClass + "getSMTPPort()";
+        String myPort = StringUtil.notNull(port);
+
+        try {
+            if (myPort.equals(StringUtil.EMPTY_STRING)) {
+                myPort = Setup.getValueRequired(getDataContext(), "MAILPort");
+            }
+        } catch (DBException dex) {
+            log.error("DB exception getting MAILPort:" + messageDetails(),
+                    dex);
+            throw new Exception(thisMethod +
+                    ":DB exception getting MAILPort:" +
+                    dex.getMessage());
+        }
+
+        port = myPort;
+
+        return myPort;
+    } /* getSMTPPort() */
 
     /**
      * This method returns the SMTP password to use for an authenticated SMTP session
@@ -434,18 +464,25 @@
     public void send() throws Exception {
         // The From header value
         String myFrom = getFromAddress();
-        if (myFrom == null || "".equals(myFrom)) {
+        if (myFrom == null || StringUtil.EMPTY_STRING.equals(myFrom)) {
             log.error("From address cannot be null. Maybe 'MAILFrom' Setup value is not set?");
             throw new Exception("'From' address cannot be null. Maybe 'MAILFrom' Setup value is not set?");
         }
 
         // The SMTP server name
         String myHost = getSMTPHost();
-        if (myHost == null || "".equals(myHost)) {
+        if (myHost == null || StringUtil.EMPTY_STRING.equals(myHost)) {
             log.error("Mail Server address cannot be null. Maybe 'MAILServer' Setup value is not set?");
             throw new Exception("Mail Server address cannot be null. Maybe 'MAILServer' Setup value is not set?");
         }
 
+        // The SMTP server name
+        String myPort = getSMTPPort();
+        if (myPort == null || StringUtil.EMPTY_STRING.equals(myPort)) {
+            log.error("Mail Port cannot be null. Maybe 'MAILPort' Setup value is not set?");
+            throw new Exception("Mail Port cannot be null. Maybe 'MAILPort' Setup value is not set?");
+        }
+
         // The SMTP user name - if null, authenticated session is not used
         String myUser = getSMTPUser();
 
@@ -501,7 +538,7 @@
         // Setup properties for the SMTP session
         Properties props = new Properties();
         props.put("mail.smtp.host", myHost); // The name of the SMTP server
-
+		props.put("mail.smtp.port", myPort); //The SMTP Port
         try {
             if (useAuth) {
 
Index: ChangeLog.xml
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/ChangeLog.xml,v
retrieving revision 1.313
retrieving revision 1.314
diff -Lexpresso-web/expresso/doc/ChangeLog.xml -Lexpresso-web/expresso/doc/ChangeLog.xml -u -r1.313 -r1.314
--- expresso-web/expresso/doc/ChangeLog.xml
+++ expresso-web/expresso/doc/ChangeLog.xml
@@ -5,6 +5,16 @@
 	<project name="Expresso">
 		<version name="5.7" releaseDate="Not released yet">
 			<comment>Continued Updates</comment>
+			<new-feature title="EMailSender sends email even in non-standard ports">
+				<explanation>The SMTP port, which defaults to 25, is now a setup value. This can be changed for mail servers not listening on the standard port. Run DBCreate to setup this new value if upgrading an old Expresso install.
+                </explanation>
+				<contributor>Francesco Galli</contributor>
+			</new-feature>
+			<new-feature title="EMailSender accepts SMTP headers">
+				<explanation>There are new methods in the EMailSender class that allows an email to have a set of custom headers.
+                </explanation>
+				<contributor>Francesco Galli</contributor>
+			</new-feature>
 			<new-feature title="Registration Controller completely i18n">
 				<explanation>The default Registration Controller (SimpleRegistration) is completely internationalized.
                 </explanation>


More information about the cvs mailing list