KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > email > SmtpsConnector


1 /*
2  * $Id: SmtpsConnector.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.email;
12
13 import org.mule.umo.lifecycle.InitialisationException;
14
15 /**
16  * Creates a secure SMTP connection
17  */

18 public class SmtpsConnector extends SmtpConnector
19 {
20
21     public static final String JavaDoc DEFAULT_SOCKET_FACTORY = "javax.net.ssl.SSLSocketFactory";
22
23     private String JavaDoc socketFactory = DEFAULT_SOCKET_FACTORY;
24     private String JavaDoc socketFactoryFallback = "false";
25     private String JavaDoc trustStore = null;
26     private String JavaDoc trustStorePassword = null;
27
28     public static final int DEFAULT_SMTPS_PORT = 465;
29
30     public SmtpsConnector() throws InitialisationException
31     {
32         super();
33     }
34
35     /*
36      * (non-Javadoc)
37      *
38      * @see org.mule.providers.UMOConnector#getProtocol()
39      */

40     public String JavaDoc getProtocol()
41     {
42         return "smtps";
43     }
44
45     public int getDefaultPort()
46     {
47         return DEFAULT_SMTPS_PORT;
48     }
49
50     public void doInitialise() throws InitialisationException
51     {
52         super.doInitialise();
53         System.setProperty("mail.smtps.ssl", "true");
54         System.setProperty("mail.smtps.socketFactory.class", getSocketFactory());
55         System.setProperty("mail.smtps.socketFactory.fallback", getSocketFactoryFallback());
56
57         /*
58          * These Properties need to be set, but if set on the System properties They
59          * will ovverwrite SMTP properties, thus effectively only letting eiter SMTP
60          * or SMTPs endpoints in 1 config. These Veriables will be set in the
61          * MailUtils, createMailSession so they will only effrect the smtps Session.
62          * System.setProperty("mail.smtp.ssl", "true");
63          * System.setProperty("mail.smtp.socketFactory.class", getSocketFactory());
64          * System.setProperty("mail.smtp.socketFactory.fallback",
65          * getSocketFactoryFallback());
66          */

67
68         if (getTrustStore() != null)
69         {
70             System.setProperty("javax.net.ssl.trustStore", getTrustStore());
71             if (getTrustStorePassword() != null)
72             {
73                 System.setProperty("javax.net.ssl.trustStorePassword", getTrustStorePassword());
74             }
75         }
76     }
77
78     public String JavaDoc getSocketFactory()
79     {
80         return socketFactory;
81     }
82
83     public void setSocketFactory(String JavaDoc sslSocketFactory)
84     {
85         this.socketFactory = sslSocketFactory;
86     }
87
88     public String JavaDoc getSocketFactoryFallback()
89     {
90         return socketFactoryFallback;
91     }
92
93     public void setSocketFactoryFallback(String JavaDoc socketFactoryFallback)
94     {
95         this.socketFactoryFallback = socketFactoryFallback;
96     }
97
98     public String JavaDoc getTrustStore()
99     {
100         return trustStore;
101     }
102
103     public void setTrustStore(String JavaDoc trustStore)
104     {
105         this.trustStore = trustStore;
106     }
107
108     public String JavaDoc getTrustStorePassword()
109     {
110         return trustStorePassword;
111     }
112
113     public void setTrustStorePassword(String JavaDoc trustStorePassword)
114     {
115         this.trustStorePassword = trustStorePassword;
116     }
117 }
118
Popular Tags