[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mail ...
Peter Muir
peter at bleepbleep.org.uk
Thu Mar 22 12:18:29 EDT 2007
User: pmuir
Date: 07/03/22 12:18:29
Modified: src/main/org/jboss/seam/mail MailSession.java
Log:
JBSEAM-864
Revision Changes Path
1.7 +66 -10 jboss-seam/src/main/org/jboss/seam/mail/MailSession.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MailSession.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mail/MailSession.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- MailSession.java 23 Feb 2007 17:12:52 -0000 1.6
+++ MailSession.java 22 Mar 2007 16:18:29 -0000 1.7
@@ -4,12 +4,16 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.io.Serializable;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.naming.NamingException;
+import javax.net.ssl.X509TrustManager;
+
import org.jboss.seam.Component;
import org.jboss.seam.InterceptionType;
import org.jboss.seam.annotations.Create;
@@ -32,17 +36,17 @@
@Intercept(InterceptionType.NEVER)
public class MailSession extends AbstractMutable implements Serializable
{
-
private static final LogProvider log = Logging.getLogProvider(MailSession.class);
private Session session;
private String host = "localhost";
- private Integer port = 25;
+ private Integer port;
private String username;
private String password;
private boolean debug = false;
private String sessionJndiName;
+ private boolean ssl;
@Unwrap
public Session getSession() throws NamingException
@@ -83,28 +87,70 @@
// Enable debugging if set
properties.put("mail.debug", isDebug());
+
+
+ if ( getUsername()!=null && getPassword()==null )
+ {
+ log.warn("username supplied without a password (if an empty password is required supply an empty string)");
+ }
+ if ( getUsername()==null && getPassword()!=null )
+ {
+ log.warn("password supplied without a username (if no authentication required supply neither)");
+ }
+
if ( getHost()!=null )
{
- properties.put("mail.host", getHost());
+ if (isSsl())
+ {
+ properties.put("mail.smtps.host", getHost());
+ }
+ else
+ {
+ properties.put("mail.smtp.host", getHost());
+ }
+
}
if ( getPort()!=null ) {
+ if (isSsl())
+ {
+ properties.put("mail.smtps.port", getPort().toString());
+ }
+ else
+ {
properties.put("mail.smtp.port", getPort().toString());
}
-
- if ( getUsername()!=null && getPassword()==null )
+ }
+ else
{
- log.warn("username supplied without a password (if an empty password is required supply an empty string)");
+ if (isSsl())
+ {
+ properties.put("mail.smtps.port", "465");
}
- if ( getUsername()==null && getPassword()!=null )
+ else
{
- log.warn("password supplied without a username (if no authentication required supply neither)");
+ properties.put("mail.smtp.port", "25");
+ }
+ }
+
+ if (isSsl())
+ {
+ properties.put("mail.transport.protocol", "smtps");
}
+
// Authentication if required
Authenticator authenticator = null;
if ( getUsername()!=null && getPassword()!=null )
{
+ if (isSsl())
+ {
+ properties.put("mail.smtps.auth", "true");
+ }
+ else
+ {
+
properties.put("mail.smtp.auth", "true");
+ }
authenticator = new Authenticator()
{
@Override
@@ -206,6 +252,16 @@
this.sessionJndiName = jndiName;
}
+ public boolean isSsl()
+ {
+ return ssl;
+ }
+
+ public void setSsl(boolean ssl)
+ {
+ this.ssl = ssl;
+ }
+
public static Session instance() {
return (Session) Component.getInstance(MailSession.class);
}
More information about the jboss-cvs-commits
mailing list