KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: SmtpConnector.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 java.util.Properties JavaDoc;
14
15 import javax.mail.Authenticator JavaDoc;
16
17 import org.mule.providers.AbstractServiceEnabledConnector;
18 import org.mule.umo.UMOComponent;
19 import org.mule.umo.UMOException;
20 import org.mule.umo.endpoint.UMOEndpoint;
21 import org.mule.umo.lifecycle.InitialisationException;
22 import org.mule.umo.provider.UMOMessageReceiver;
23
24 /**
25  * <code>SmtpConnector</code> is used to connect to and send data to an SMTP mail
26  * server
27  */

28 public class SmtpConnector extends AbstractServiceEnabledConnector implements MailConnector
29 {
30     public static final String JavaDoc DEFAULT_SMTP_HOST = "localhost";
31     public static final int DEFAULT_SMTP_PORT = 25;
32     public static final String JavaDoc DEFAULT_CONTENT_TYPE = "text/plain";
33
34     private String JavaDoc host = DEFAULT_SMTP_HOST;
35     private int port = DEFAULT_SMTP_PORT;
36     private String JavaDoc username;
37     private String JavaDoc password;
38
39     /**
40      * Holds value of bcc addresses.
41      */

42     private String JavaDoc bcc;
43
44     /**
45      * Holds value of cc addresses.
46      */

47     private String JavaDoc cc;
48
49     /**
50      * Holds value of replyTo addresses.
51      */

52     private String JavaDoc replyTo;
53
54     /**
55      * Holds value of default subject
56      */

57     private String JavaDoc defaultSubject = "[No Subject]";
58
59     /**
60      * Holds value of the from address.
61      */

62     private String JavaDoc from;
63
64     /**
65      * Any custom headers to be set on messages sent using this connector
66      */

67     private Properties JavaDoc customHeaders = new Properties JavaDoc();
68
69     /**
70      * A custom authenticator to be used on any mail sessions created with this
71      * connector This will only be used if user name credentials are set on the
72      * endpoint
73      */

74     private Authenticator JavaDoc authenticator = null;
75
76     private String JavaDoc contentType = DEFAULT_CONTENT_TYPE;
77
78     public SmtpConnector() throws InitialisationException
79     {
80         initFromServiceDescriptor();
81     }
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see org.mule.providers.UMOConnector#registerListener(javax.jms.MessageListener,
87      * java.lang.String)
88      */

89     public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception JavaDoc
90     {
91         throw new UnsupportedOperationException JavaDoc("Listeners cannot be registered on a SMTP endpoint");
92     }
93
94     /*
95      * @see org.mule.providers.UMOConnector#start()
96      */

97     public void doStart() throws UMOException
98     {
99         // template method
100
}
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see org.mule.providers.UMOConnector#stop()
106      */

107     public void doStop() throws UMOException
108     {
109         // template method
110
}
111
112     /*
113      * (non-Javadoc)
114      *
115      * @see org.mule.providers.AbstractConnector#doDispose()
116      */

117     protected void doDispose()
118     {
119         try
120         {
121             doStop();
122         }
123         catch (UMOException e)
124         {
125             logger.error(e.getMessage(), e);
126         }
127     }
128
129     public String JavaDoc getProtocol()
130     {
131         return "smtp";
132     }
133
134     // ///////////////////////////////////////////////////////////////////////
135
// Getters and setters
136
// ///////////////////////////////////////////////////////////////////////
137

138     /**
139      * @return The default from address to use
140      */

141     public String JavaDoc getFromAddress()
142     {
143         return from;
144     }
145
146     /**
147      * @return the default comma separated list of BCC addresses to use
148      */

149     public String JavaDoc getBccAddresses()
150     {
151         return bcc;
152     }
153
154     /**
155      * @return the default comma separated list of CC addresses to use
156      */

157     public String JavaDoc getCcAddresses()
158     {
159         return cc;
160     }
161
162     /**
163      * @return the default message subject to use
164      */

165     public String JavaDoc getSubject()
166     {
167         return defaultSubject;
168     }
169
170     public void setBccAddresses(String JavaDoc string)
171     {
172         bcc = string;
173     }
174
175     public void setCcAddresses(String JavaDoc string)
176     {
177         cc = string;
178     }
179
180     public void setSubject(String JavaDoc string)
181     {
182         defaultSubject = string;
183     }
184
185     public void setFromAddress(String JavaDoc string)
186     {
187         from = string;
188     }
189
190     public String JavaDoc getReplyToAddresses()
191     {
192         return replyTo;
193     }
194
195     public void setReplyToAddresses(String JavaDoc replyTo)
196     {
197         this.replyTo = replyTo;
198     }
199
200     public Properties JavaDoc getCustomHeaders()
201     {
202         return customHeaders;
203     }
204
205     public void setCustomHeaders(Properties JavaDoc customHeaders)
206     {
207         this.customHeaders = customHeaders;
208     }
209
210     public Authenticator JavaDoc getAuthenticator()
211     {
212         return authenticator;
213     }
214
215     public void setAuthenticator(Authenticator JavaDoc authenticator)
216     {
217         this.authenticator = authenticator;
218     }
219
220     public String JavaDoc getContentType()
221     {
222         return contentType;
223     }
224
225     public void setContentType(String JavaDoc contentType)
226     {
227         this.contentType = contentType;
228     }
229
230     public int getDefaultPort()
231     {
232         return DEFAULT_SMTP_PORT;
233     }
234
235     public String JavaDoc getHost()
236     {
237         return host;
238     }
239
240     public void setHost(String JavaDoc host)
241     {
242         this.host = host;
243     }
244
245     public String JavaDoc getPassword()
246     {
247         return password;
248     }
249
250     public void setPassword(String JavaDoc password)
251     {
252         this.password = password;
253     }
254
255     public int getPort()
256     {
257         return port;
258     }
259
260     public void setPort(int port)
261     {
262         this.port = port;
263     }
264
265     public String JavaDoc getUsername()
266     {
267         return username;
268     }
269
270     public void setUsername(String JavaDoc username)
271     {
272         this.username = username;
273     }
274 }
275
Popular Tags