### Eclipse Workspace Patch 1.0
#P JSPWiki
Index: src/com/ecyrd/jspwiki/util/MailUtil.java
===================================================================
RCS file: /p/cvs/JSPWiki/src/com/ecyrd/jspwiki/util/MailUtil.java,v
retrieving revision 1.12
diff -u -r1.12 MailUtil.java
--- src/com/ecyrd/jspwiki/util/MailUtil.java	25 Dec 2007 22:43:00 -0000	1.12
+++ src/com/ecyrd/jspwiki/util/MailUtil.java	1 Jan 2008 12:34:28 -0000
@@ -198,6 +198,8 @@
 
     private static final String TRUE = "true";
 
+    private static boolean useJndi = false;
+
     public static final String PROP_MAIL_AUTH = "mail.smtp.auth";
 
     protected static final Logger log = Logger.getLogger(MailUtil.class);
@@ -294,17 +296,19 @@
         Properties props = engine.getWikiProperties();
         String jndiName = props.getProperty( PROP_MAIL_JNDI_NAME, DEFAULT_MAIL_JNDI_NAME ).trim();
         Session session = null;
-        boolean useJndi = false;
 
-        // Try getting the Session from the JNDI factory first
-        try
-        {
-            session = getJNDIMailSession( jndiName );
-            useJndi = true;
-        }
-        catch ( NamingException e )
+        if (useJndi)
         {
-            // Oops! JNDI factory must not be set up
+            // Try getting the Session from the JNDI factory first
+            try
+            {
+                session = getJNDIMailSession(jndiName);
+                useJndi = true;
+            }
+            catch (NamingException e)
+            {
+                // Oops! JNDI factory must not be set up
+            }
         }
 
         // JNDI failed; so, get the Session from the standalone factory
