KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > mail > SMTPTransportGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.mail;
18
19 import java.util.Properties JavaDoc;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26
27 /**
28  * A GBean that provides for the configuration of a JavaMail SMTP transport
29  * protocol.
30  * <p/>
31  * SMTP transport properties that are common to all SMTP transports are
32  * provided via member variables of this class. Values that are set in the
33  * individual member variables will override any of the corresponding values
34  * that have been set in the properties set.
35  *
36  * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
37  * @see MailGBean
38  */

39 public class SMTPTransportGBean extends ProtocolGBean {
40
41     // the SMTP configuration property names
42
static public final String JavaDoc SMTP_PORT = "mail.smtp.port";
43     static public final String JavaDoc SMTP_CONNECTION_TIMEOUT = "mail.smtp.connectiontimeout";
44     static public final String JavaDoc SMTP_TIMEOUT = "mail.smtp.timeout";
45     static public final String JavaDoc SMTP_FROM = "mail.smtp.from";
46     static public final String JavaDoc SMTP_AUTH = "mail.smtp.auth";
47     static public final String JavaDoc SMTP_REALM = "mail.smtp.sasl.realm";
48     static public final String JavaDoc SMTP_QUITWAIT = "mail.smtp.quitwait";
49     static public final String JavaDoc SMTP_FACTORY_CLASS = "mail.smtp.socketFactory.class";
50     static public final String JavaDoc SMTP_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
51     static public final String JavaDoc SMTP_FACTORY_PORT = "mail.smtp.socketFactory.port";
52     static public final String JavaDoc SMTP_LOCALHOST = "mail.smtp.localhost";
53     static public final String JavaDoc SMTP_LOCALADDRESS = "mail.smtp.localaddress";
54     static public final String JavaDoc SMTP_LOCALPORT = "mail.smtp.localport";
55     static public final String JavaDoc SMTP_EHLO = "mail.smtp.ehlo";
56     static public final String JavaDoc SMTP_SUBMITTER = "mail.smtp.submitter";
57     static public final String JavaDoc SMTP_DSN_NOTIFY = "mail.smtp.dsn.notify";
58     static public final String JavaDoc SMTP_DSN_RET = "mail.smtp.dsn.ret";
59     static public final String JavaDoc SMTP_8BITMIME = "mail.smtp.allow8bitmime";
60     static public final String JavaDoc SMTP_SEND_PARTIAL = "mail.smtp.sendpartial";
61     static public final String JavaDoc SMTP_REPORT_SUCCESS = "mail.smtp.reportsuccess";
62     static public final String JavaDoc SMTP_MAIL_EXTENSION = "mail.smtp.mailextension";
63     static public final String JavaDoc SMTP_STARTTLS_ENABLE = "mail.smtp.starttls.enable";
64
65     static public final String JavaDoc GBEAN_EHLO = "ehlo";
66     static public final String JavaDoc GBEAN_SUBMITTER = "submitter";
67     static public final String JavaDoc GBEAN_DSN_NOTIFY = "dsnNotify";
68     static public final String JavaDoc GBEAN_DSN_RET = "dsnRet";
69     static public final String JavaDoc GBEAN_8BITMIME = "allow8bitmime";
70     static public final String JavaDoc GBEAN_SEND_PARTIAL = "sendPartical";
71     static public final String JavaDoc GBEAN_REPORT_SUCCESS = "reportSuccess";
72     static public final String JavaDoc GBEAN_MAIL_EXTENSION = "mailExtension";
73 static public final String JavaDoc GBEAN_STARTTLS_ENABLE = "startTLSEnable";
74
75
76     private final Log log = LogFactory.getLog(SMTPTransportGBean.class);
77
78     private Integer JavaDoc port;
79     private Integer JavaDoc connectionTimeout;
80     private Integer JavaDoc timeout;
81     private String JavaDoc from;
82     private String JavaDoc localhost;
83     private String JavaDoc localaddress;
84     private Integer JavaDoc localport;
85     private Boolean JavaDoc ehlo;
86     private Boolean JavaDoc auth;
87     private String JavaDoc submitter;
88     private String JavaDoc dsnNotify;
89     private String JavaDoc dsnRet;
90     private Boolean JavaDoc allow8bitmime;
91     private Boolean JavaDoc sendPartial;
92     private String JavaDoc saslRealm;
93     private Boolean JavaDoc quitWait;
94     private Boolean JavaDoc reportSuccess;
95     private String JavaDoc socketFactoryClass;
96     private Boolean JavaDoc socketFactoryFallback;
97     private Integer JavaDoc socketFactoryPort;
98     private String JavaDoc mailExtension;
99     private Boolean JavaDoc startTLSEnable;
100
101
102     /**
103      * Construct an instance of SMTPTransportGBean
104      * <p/>
105      * Values that are set in the individual member variables will override any of
106      * the corresponding values that have been set in the properties set.
107      *
108      * @param objectName the object name of the protocol
109      * @param properties the set of default properties for the protocol
110      * @param host the host the protocol connects to
111      * @param user the default name for the protocol
112      * @param port the SMTP server port
113      * @param connectionTimeout the socket connection timeout value in milliseconds
114      * @param timeout the socket I/O timeout value in milliseconds
115      * @param from the email address to use for SMTP MAIL command
116      * @param localhost the local host name used in the SMTP HELO or EHLO command
117      * @param localaddress the local address (host name) to bind to when creating the SMTP socket
118      * @param localport the local port number to bind to when creating the SMTP socket
119      * @param ehlo whether an attempt will be made to sign on with the EHLO command
120      * @param auth whether an attempt will be made to authenticate the user using
121      * the AUTH command
122      * @param startTLSEnable the flag that enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands
123      * @param submitter the submitter to use in the AUTH tag in the MAIL FROM command
124      * @param dsnNotify the NOTIFY option to the RCPT command
125      * @param dsnRet the RET option to the MAIL command
126      * @param allow8bitmime whether encodings are converted to use "8bit" under certain
127      * conditions
128      * @param sendPartial whether to send email to valid addresses when others are invalid
129      * @param saslRealm the realm to use with DIGEST-MD5 authentication
130      * @param quitWait whether the transport will wait for the response to the QUIT command
131      * @param reportSuccess whether the transport will include an SMTPAddressSucceededException
132      * for each address that is successful
133      * @param socketFactoryClass the class that will be used to create SMTP sockets
134      * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
135      * socket factory class cannot be created
136      * @param socketFactoryPort whether java.net.Socket class will be created if the specified
137      * socket factory class cannot be created
138      * @param mailExtension the extension string to append to the MAIL command
139      */

140     public SMTPTransportGBean(String JavaDoc objectName, Properties JavaDoc properties, String JavaDoc host, String JavaDoc user,
141                               Integer JavaDoc port,
142                               Integer JavaDoc connectionTimeout,
143                               Integer JavaDoc timeout,
144                               String JavaDoc from,
145                               String JavaDoc localhost,
146                               String JavaDoc localaddress,
147                               Integer JavaDoc localport,
148                               Boolean JavaDoc ehlo,
149                               Boolean JavaDoc auth,
150                               Boolean JavaDoc startTLSEnable,
151                               String JavaDoc submitter,
152                               String JavaDoc dsnNotify,
153                               String JavaDoc dsnRet,
154                               Boolean JavaDoc allow8bitmime,
155                               Boolean JavaDoc sendPartial,
156                               String JavaDoc saslRealm,
157                               Boolean JavaDoc quitWait,
158                               Boolean JavaDoc reportSuccess,
159                               String JavaDoc socketFactoryClass,
160                               Boolean JavaDoc socketFactoryFallback,
161                               Integer JavaDoc socketFactoryPort,
162                               String JavaDoc mailExtension) {
163         super(objectName, "smtp", properties, host, user);
164
165         setPort(port);
166         setConnectionTimeout(connectionTimeout);
167         setTimeout(timeout);
168         setFrom(from);
169         setLocalhost(localhost);
170         setLocaladdress(localaddress);
171         setLocalport(localport);
172         setEhlo(ehlo);
173         setAuth(auth);
174         setStartTLSEnable(startTLSEnable);
175         setSubmitter(submitter);
176         setDsnNotify(dsnNotify);
177         setDsnRet(dsnRet);
178         setAllow8bitmime(allow8bitmime);
179         setSendPartial(sendPartial);
180         setSaslRealm(saslRealm);
181         setQuitWait(quitWait);
182         setReportSuccess(reportSuccess);
183         setSocketFactoryClass(socketFactoryClass);
184         setSocketFactoryFallback(socketFactoryFallback);
185         setSocketFactoryPort(socketFactoryPort);
186         setMailExtension(mailExtension);
187     }
188
189     /**
190      * Returns the SMTP server port to connect to, if the connect() method
191      * doesn't explicitly specify one.
192      */

193     public Integer JavaDoc getPort() {
194         return port;
195     }
196
197     /**
198      * Sets the SMTP server port to connect to, if the connect() method
199      * doesn't explicitly specify one.
200      * <p/>
201      * Defaults to 25.
202      * <p/>
203      * Values that are set here will override any of the corresponding value
204      * that has been set in the properties.
205      *
206      * @param port the SMTP server port to connect to
207      */

208     public void setPort(Integer JavaDoc port) {
209         this.port = port;
210     }
211
212     /**
213      * Returns the socket connection timeout value in milliseconds.
214      */

215     public Integer JavaDoc getConnectionTimeout() {
216         return connectionTimeout;
217     }
218
219     /**
220      * Sets the socket connection timeout value in milliseconds.
221      * <p/>
222      * Default is infinite timeout.
223      * <p/>
224      * Values that are set here will override any of the corresponding value
225      * that has been set in the properties.
226      *
227      * @param connectionTimeout the socket connection timeout value in milliseconds.
228      */

229     public void setConnectionTimeout(Integer JavaDoc connectionTimeout) {
230         this.connectionTimeout = connectionTimeout;
231     }
232
233     /**
234      * Returns the socket I/O timeout value in milliseconds.
235      */

236     public Integer JavaDoc getTimeout() {
237         return timeout;
238     }
239
240     /**
241      * Sets the socket I/O timeout value in milliseconds.
242      * <p/>
243      * Default is infinite timeout.
244      * <p/>
245      * Values that are set here will override any of the corresponding value
246      * that has been set in the properties.
247      *
248      * @param timeout the socket I/O timeout value in milliseconds
249      */

250     public void setTimeout(Integer JavaDoc timeout) {
251         this.timeout = timeout;
252     }
253
254     /**
255      * Returns the email address to use for SMTP MAIL command.
256      */

257     public String JavaDoc getFrom() {
258         return from;
259     }
260
261     /**
262      * Sets the email address to use for SMTP MAIL command
263      * <p/>
264      * Email address to use for SMTP MAIL command. This sets the envelope
265      * return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress().
266      * NOTE: mail.smtp.user was previously used for this.
267      * <p/>
268      * Values that are set here will override any of the corresponding value
269      * that has been set in the properties.
270      *
271      * @param from the email address to use for SMTP MAIL command
272      */

273     public void setFrom(String JavaDoc from) {
274         this.from = from;
275     }
276
277     /**
278      * Returns the local host name used in the SMTP HELO or EHLO command.
279      */

280     public String JavaDoc getLocalhost() {
281         return localhost;
282     }
283
284     /**
285      * Sets the local host name used in the SMTP HELO or EHLO command.
286      * <p/>
287      * Local host name used in the SMTP HELO or EHLO command. Defaults to
288      * InetAddress.getLocalHost().getHostName(). Should not normally need to
289      * be set if your JDK and your name service are configured properly.
290      * <p/>
291      * Values that are set here will override any of the corresponding value
292      * that has been set in the properties.
293      *
294      * @param localhost the local host name used in the SMTP HELO or EHLO command
295      */

296     public void setLocalhost(String JavaDoc localhost) {
297         this.localhost = localhost;
298     }
299
300     /**
301      * Returns the local address (host name) to bind to when creating the SMTP socket.
302      */

303     public String JavaDoc getLocaladdress() {
304         return localaddress;
305     }
306
307     /**
308      * Sets the local address (host name) to bind to when creating the SMTP socket.
309      * <p/>
310      * Local address (host name) to bind to when creating the SMTP socket.
311      * Defaults to the address picked by the Socket class. Should not normally
312      * need to be set, but useful with multi-homed hosts where it's important
313      * to pick a particular local address to bind to.
314      * <p/>
315      * Values that are set here will override any of the corresponding value
316      * that has been set in the properties.
317      *
318      * @param localaddress the local address (host name) to bind to when creating the SMTP socket
319      */

320     public void setLocaladdress(String JavaDoc localaddress) {
321         this.localaddress = localaddress;
322     }
323
324     /**
325      * Returns the local port number to bind to when creating the SMTP socket.
326      */

327     public Integer JavaDoc getLocalport() {
328         return localport;
329     }
330
331     /**
332      * Sets the local port number to bind to when creating the SMTP socket.
333      * <p/>
334      * Local port number to bind to when creating the SMTP socket. Defaults to
335      * the port number picked by the Socket class.
336      * <p/>
337      * Values that are set here will override any of the corresponding value
338      * that has been set in the properties.
339      *
340      * @param localport the local port number to bind to when creating the SMTP socket
341      */

342     public void setLocalport(Integer JavaDoc localport) {
343         this.localport = localport;
344     }
345
346     /**
347      * Returns whether an attempt will be made to sign on with the EHLO command.
348      * <p/>
349      * If false, do not attempt to sign on with the EHLO command. Normally
350      * failure of the EHLO command will fallback to the HELO command; this
351      * property exists only for servers that don't fail EHLO properly or don't
352      * implement EHLO properly.
353      */

354     public Boolean JavaDoc getEhlo() {
355         return ehlo;
356     }
357
358     /**
359      * Set whether an attempt will be made to sign on with the EHLO command.
360      * <p/>
361      * If false, do not attempt to sign on with the EHLO command. Normally
362      * failure of the EHLO command will fallback to the HELO command; this
363      * property exists only for servers that don't fail EHLO properly or don't
364      * implement EHLO properly.
365      * <p/>
366      * Values that are set here will override any of the corresponding value
367      * that has been set in the properties.
368      *
369      * @param ehlo whether an attempt will be made to sign on with the EHLO command
370      */

371     public void setEhlo(Boolean JavaDoc ehlo) {
372         this.ehlo = ehlo;
373     }
374
375     /**
376      * Returns whether an attempt will be made to authenticate the user using
377      * the AUTH command.
378      * <p/>
379      * Defaults to false.
380      */

381     public Boolean JavaDoc getAuth() {
382         return auth;
383     }
384
385     /**
386      * Sets whether an attempt will be made to authenticate the user using
387      * the AUTH command.
388      * <p/>
389      * Defaults to false.
390      * <p/>
391      * Values that are set here will override any of the corresponding value
392      * that has been set in the properties.
393      *
394      * @param auth whether an attempt will be made to authenticate the user using
395      * the AUTH command.
396      */

397     public void setAuth(Boolean JavaDoc auth) {
398         this.auth = auth;
399     }
400
401     /**
402      * Returns the flag that enables the use of the STARTTLS command (if
403      * supported by the server) to switch the connection to a TLS-protected
404      * connection before issuing any login commands.
405      * <p/>
406      * If true, enables the use of the STARTTLS command (if supported by the
407      * server) to switch the connection to a TLS-protected connection before
408      * issuing any login commands. Note that an appropriate trust store must
409      * configured so that the client will trust the server's certificate.
410      * This feature only works on J2SE 1.4 and newer systems. Default is false.
411      */

412     public Boolean JavaDoc getStartTLSEnable() {
413         return startTLSEnable;
414     }
415
416     /**
417      * Sets the flag that enables the use of the STARTTLS command (if
418      * supported by the server) to switch the connection to a TLS-protected
419      * connection before issuing any login commands.
420      * <p/>
421      * If true, enables the use of the STARTTLS command (if supported by the
422      * server) to switch the connection to a TLS-protected connection before
423      * issuing any login commands. Note that an appropriate trust store must
424      * configured so that the client will trust the server's certificate.
425      * This feature only works on J2SE 1.4 and newer systems. Default is false.
426      * <p/>
427      * Values that are set here will override any of the corresponding value
428      * that has been set in the properties.
429      *
430      * @param startTLSEnable the flag that enables the use of the STARTTLS command (if
431      * supported by the server) to switch the connection to a TLS-protected
432      * connection before issuing any login commands
433      */

434     public void setStartTLSEnable(Boolean JavaDoc startTLSEnable) {
435         this.startTLSEnable = startTLSEnable;
436     }
437
438     /**
439      * Returns the submitter to use in the AUTH tag in the MAIL FROM command.
440      * <p/>
441      * Typically used by a mail relay to pass along information about the
442      * original submitter of the message. See also the setSubmitter method of
443      * SMTPMessage. Mail clients typically do not use this.
444      */

445     public String JavaDoc getSubmitter() {
446         return submitter;
447     }
448
449     /**
450      * Sets the submitter to use in the AUTH tag in the MAIL FROM command.
451      * <p/>
452      * Typically used by a mail relay to pass along information about the
453      * original submitter of the message. See also the setSubmitter method of
454      * SMTPMessage. Mail clients typically do not use this.
455      * <p/>
456      * Values that are set here will override any of the corresponding value
457      * that has been set in the properties.
458      *
459      * @param submitter the submitter to use in the AUTH tag in the MAIL FROM command
460      */

461     public void setSubmitter(String JavaDoc submitter) {
462         this.submitter = submitter;
463     }
464
465     /**
466      * Returns the NOTIFY option to the RCPT command.
467      * <p/>
468      * Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY
469      * (separated by commas).
470      */

471     public String JavaDoc getDsnNotify() {
472         return dsnNotify;
473     }
474
475     /**
476      * Sets the NOTIFY option to the RCPT command
477      * <p/>
478      * Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY
479      * (separated by commas).
480      * <p/>
481      * Values that are set here will override any of the corresponding value
482      * that has been set in the properties.
483      *
484      * @param dsnNotify the NOTIFY option to the RCPT command
485      */

486     public void setDsnNotify(String JavaDoc dsnNotify) {
487         this.dsnNotify = dsnNotify;
488     }
489
490     /**
491      * Returns the RET option to the MAIL command.
492      * <p/>
493      * Either FULL or HDRS.
494      */

495     public String JavaDoc getDsnRet() {
496         return dsnRet;
497     }
498
499     /**
500      * Sets the RET option to the MAIL command
501      * <p/>
502      * Either FULL or HDRS.
503      * <p/>
504      * Values that are set here will override any of the corresponding value
505      * that has been set in the properties.
506      *
507      * @param dsnRet the RET option to the MAIL command
508      */

509     public void setDsnRet(String JavaDoc dsnRet) {
510         this.dsnRet = dsnRet;
511     }
512
513     /**
514      * Returns whether encodings are converted to use "8bit" under certain
515      * conditions.
516      * <p/>
517      * If set to true, and the server supports the 8BITMIME extension, text
518      * parts of messages that use the "quoted-printable" or "base64" encodings
519      * are converted to use "8bit" encoding if they follow the RFC2045 rules
520      * for 8bit text.
521      */

522     public Boolean JavaDoc getAllow8bitmime() {
523         return allow8bitmime;
524     }
525
526     /**
527      * Sets whether encodings are converted to use "8bit" under certain
528      * conditions.
529      * <p/>
530      * If set to true, and the server supports the 8BITMIME extension, text
531      * parts of messages that use the "quoted-printable" or "base64" encodings
532      * are converted to use "8bit" encoding if they follow the RFC2045 rules
533      * for 8bit text.
534      * <p/>
535      * Values that are set here will override any of the corresponding value
536      * that has been set in the properties.
537      *
538      * @param allow8bitmime whether encodings are converted to use "8bit" under certain
539      * conditions
540      */

541     public void setAllow8bitmime(Boolean JavaDoc allow8bitmime) {
542         this.allow8bitmime = allow8bitmime;
543     }
544
545     /**
546      * Returns whether to send email to valid addresses when others are invalid.
547      * <p/>
548      * If set to true, and a message has some valid and some invalid addresses,
549      * send the message anyway, reporting the partial failure with a
550      * SendFailedException. If set to false (the default), the message is not
551      * sent to any of the recipients if there is an invalid recipient address.
552      */

553     public Boolean JavaDoc getSendPartial() {
554         return sendPartial;
555     }
556
557     /**
558      * Sets whether to send email to valid addresses when others are invalid.
559      * <p/>
560      * If set to true, and a message has some valid and some invalid addresses,
561      * send the message anyway, reporting the partial failure with a
562      * SendFailedException. If set to false (the default), the message is not
563      * sent to any of the recipients if there is an invalid recipient address.
564      * <p/>
565      * Values that are set here will override any of the corresponding value
566      * that has been set in the properties.
567      *
568      * @param sendPartial whether to send email to valid addresses when others are invalid
569      */

570     public void setSendPartial(Boolean JavaDoc sendPartial) {
571         this.sendPartial = sendPartial;
572     }
573
574     /**
575      * Returns the realm to use with DIGEST-MD5 authentication.
576      */

577     public String JavaDoc getSaslRealm() {
578         return saslRealm;
579     }
580
581     /**
582      * Sets the realm to use with DIGEST-MD5 authentication.
583      * <p/>
584      * Values that are set here will override any of the corresponding value
585      * that has been set in the properties.
586      *
587      * @param saslRealm the realm to use with DIGEST-MD5 authentication
588      */

589     public void setSaslRealm(String JavaDoc saslRealm) {
590         this.saslRealm = saslRealm;
591     }
592
593     /**
594      * Returns whether the transport will wait for the response to the QUIT command.
595      * <p/>
596      * If set to true, causes the transport to wait for the response to the QUIT
597      * command. If set to false (the default), the QUIT command is sent and the
598      * connection is immediately closed.
599      */

600     public Boolean JavaDoc getQuitWait() {
601         return quitWait;
602     }
603
604     /**
605      * Sets whether the transport will wait for the response to the QUIT command
606      * <p/>
607      * If set to true, causes the transport to wait for the response to the QUIT
608      * command. If set to false (the default), the QUIT command is sent and the
609      * connection is immediately closed.
610      * <p/>
611      * Values that are set here will override any of the corresponding value
612      * that has been set in the properties.
613      *
614      * @param quitWait whether the transport will wait for the response to the QUIT command
615      */

616     public void setQuitWait(Boolean JavaDoc quitWait) {
617         this.quitWait = quitWait;
618     }
619
620     /**
621      * Returns whether the transport will include an SMTPAddressSucceededException
622      * for each address that is successful.
623      * <p/>
624      * Note also that this will cause a SendFailedException to be thrown from
625      * the sendMessage method of SMTPTransport even if all addresses were
626      * correct and the message was sent successfully.
627      */

628     public Boolean JavaDoc getReportSuccess() {
629         return reportSuccess;
630     }
631
632     /**
633      * Sets whether the transport will include an SMTPAddressSucceededException
634      * for each address that is successful.
635      * <p/>
636      * Note also that this will cause a SendFailedException to be thrown from
637      * the sendMessage method of SMTPTransport even if all addresses were
638      * correct and the message was sent successfully.
639      * <p/>
640      * Values that are set here will override any of the corresponding value
641      * that has been set in the properties.
642      *
643      * @param reportSuccess whether the transport will include an SMTPAddressSucceededException
644      * for each address that is successful
645      */

646     public void setReportSuccess(Boolean JavaDoc reportSuccess) {
647         this.reportSuccess = reportSuccess;
648     }
649
650     /**
651      * Returns the class that will be used to create SMTP sockets.
652      * <p/>
653      * If set, specifies the name of a class that implements the
654      * javax.net.SocketFactory interface. This class will be used to create SMTP
655      * sockets.
656      */

657     public String JavaDoc getSocketFactoryClass() {
658         return socketFactoryClass;
659     }
660
661     /**
662      * Sets the class that will be used to create SMTP sockets.
663      * <p/>
664      * If set, specifies the name of a class that implements the
665      * javax.net.SocketFactory interface. This class will be used to create SMTP
666      * sockets.
667      * <p/>
668      * Values that are set here will override any of the corresponding value
669      * that has been set in the properties.
670      *
671      * @param socketFactoryClass the class that will be used to create SMTP sockets
672      */

673     public void setSocketFactoryClass(String JavaDoc socketFactoryClass) {
674         this.socketFactoryClass = socketFactoryClass;
675     }
676
677     /**
678      * Returns whether java.net.Socket class will be created if the specified
679      * socket factory class cannot be created.
680      * <p/>
681      * If set to true, failure to create a socket using the specified socket
682      * factory class will cause the socket to be created using the
683      * java.net.Socket class. Defaults to true.
684      */

685     public Boolean JavaDoc getSocketFactoryFallback() {
686         return socketFactoryFallback;
687     }
688
689     /**
690      * Sets whether java.net.Socket class will be created if the specified
691      * socket factory class cannot be created.
692      * <p/>
693      * If set to true, failure to create a socket using the specified socket
694      * factory class will cause the socket to be created using the
695      * java.net.Socket class. Defaults to true.
696      * <p/>
697      * Values that are set here will override any of the corresponding value
698      * that has been set in the properties.
699      *
700      * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
701      * socket factory class cannot be created
702      */

703     public void setSocketFactoryFallback(Boolean JavaDoc socketFactoryFallback) {
704         this.socketFactoryFallback = socketFactoryFallback;
705     }
706
707     /**
708      * Returns the port to connect to when using the specified socket factory.
709      * <p/>
710      * Specifies the port to connect to when using the specified socket
711      * factory. If not set, the default port will be used.
712      */

713     public Integer JavaDoc getSocketFactoryPort() {
714         return socketFactoryPort;
715     }
716
717     /**
718      * Sets the port to connect to when using the specified socket factory.
719      * <p/>
720      * Specifies the port to connect to when using the specified socket
721      * factory. If not set, the default port will be used.
722      * <p/>
723      * Values that are set here will override any of the corresponding value
724      * that has been set in the properties.
725      *
726      * @param socketFactoryPort the port to connect to when using the specified socket factory
727      */

728     public void setSocketFactoryPort(Integer JavaDoc socketFactoryPort) {
729         this.socketFactoryPort = socketFactoryPort;
730     }
731
732     /**
733      * Returns the extension string to append to the MAIL command.
734      * <p/>
735      * Extension string to append to the MAIL command. The extension string
736      * can be used to specify standard SMTP service extensions as well as
737      * vendor-specific extensions. Typically the application should use the
738      * SMTPTransport method supportsExtension to verify that the server
739      * supports the desired service extension. See RFC 1869 and other RFCs
740      * that define specific extensions.
741      */

742     public String JavaDoc getMailExtension() {
743         return mailExtension;
744     }
745
746     /**
747      * Sets the extension string to append to the MAIL command.
748      * <p/>
749      * Extension string to append to the MAIL command. The extension string
750      * can be used to specify standard SMTP service extensions as well as
751      * vendor-specific extensions. Typically the application should use the
752      * SMTPTransport method supportsExtension to verify that the server
753      * supports the desired service extension. See RFC 1869 and other RFCs
754      * that define specific extensions.
755      * <p/>
756      * Values that are set here will override any of the corresponding value
757      * that has been set in the properties.
758      *
759      * @param mailExtension the extension string to append to the MAIL command
760      */

761     public void setMailExtension(String JavaDoc mailExtension) {
762         this.mailExtension = mailExtension;
763     }
764
765     /**
766      * Add the overrides from the member variables to the properties file.
767      */

768     public void addOverrides(Properties JavaDoc props) {
769         super.addOverrides(props);
770
771         if (port != null) props.setProperty(SMTP_PORT, port.toString());
772         if (connectionTimeout != null) props.setProperty(SMTP_CONNECTION_TIMEOUT, connectionTimeout.toString());
773         if (timeout != null) props.setProperty(SMTP_TIMEOUT, timeout.toString());
774         if (from != null) props.setProperty(SMTP_FROM, from);
775         if (localhost != null) props.setProperty(SMTP_LOCALHOST, localhost);
776         if (localaddress != null) props.setProperty(SMTP_LOCALADDRESS, localaddress);
777         if (localport != null) props.setProperty(SMTP_LOCALPORT, localport.toString());
778         if (ehlo != null) props.setProperty(SMTP_EHLO, ehlo.toString());
779         if (auth != null) props.setProperty(SMTP_AUTH, auth.toString());
780         if (startTLSEnable != null) props.setProperty(SMTP_STARTTLS_ENABLE, startTLSEnable.toString());
781         if (submitter != null) props.setProperty(SMTP_SUBMITTER, submitter);
782         if (dsnNotify != null) props.setProperty(SMTP_DSN_NOTIFY, dsnNotify);
783         if (dsnRet != null) props.setProperty(SMTP_DSN_RET, dsnRet);
784         if (allow8bitmime != null) props.setProperty(SMTP_8BITMIME, allow8bitmime.toString());
785         if (sendPartial != null) props.setProperty(SMTP_SEND_PARTIAL, sendPartial.toString());
786         if (saslRealm != null) props.setProperty(SMTP_REALM, saslRealm);
787         if (quitWait != null) props.setProperty(SMTP_QUITWAIT, quitWait.toString());
788         if (reportSuccess != null) props.setProperty(SMTP_REPORT_SUCCESS, reportSuccess.toString());
789         if (socketFactoryClass != null) props.setProperty(SMTP_FACTORY_CLASS, socketFactoryClass);
790         if (socketFactoryFallback != null) props.setProperty(SMTP_FACTORY_FALLBACK, socketFactoryFallback.toString());
791         if (socketFactoryPort != null) props.setProperty(SMTP_FACTORY_PORT, socketFactoryPort.toString());
792         if (mailExtension != null) props.setProperty(SMTP_MAIL_EXTENSION, mailExtension);
793     }
794
795     public void doStart() throws Exception JavaDoc {
796         log.debug("Started " + getObjectName());
797     }
798
799     public void doStop() throws Exception JavaDoc {
800         log.debug("Stopped " + getObjectName());
801     }
802
803     public void doFail() {
804         log.warn("Failed " + getObjectName());
805     }
806
807     public static final GBeanInfo GBEAN_INFO;
808
809     static {
810         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(SMTPTransportGBean.class);
811
812         infoFactory.addAttribute(GBEAN_PORT, Integer JavaDoc.class, true);
813         infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer JavaDoc.class, true);
814         infoFactory.addAttribute(GBEAN_TIMEOUT, Integer JavaDoc.class, true);
815         infoFactory.addAttribute(GBEAN_AUTH, Boolean JavaDoc.class, true);
816         infoFactory.addAttribute(GBEAN_STARTTLS_ENABLE, Boolean JavaDoc.class, true);
817         infoFactory.addAttribute(GBEAN_EHLO, Boolean JavaDoc.class, true);
818         infoFactory.addAttribute(GBEAN_FROM, String JavaDoc.class, true);
819         infoFactory.addAttribute(GBEAN_LOCALHOST, String JavaDoc.class, true);
820         infoFactory.addAttribute(GBEAN_LOCALADDRESS, String JavaDoc.class, true);
821         infoFactory.addAttribute(GBEAN_LOCALPORT, Integer JavaDoc.class, true);
822         infoFactory.addAttribute(GBEAN_REALM, String JavaDoc.class, true);
823         infoFactory.addAttribute(GBEAN_QUITWAIT, Boolean JavaDoc.class, true);
824         infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String JavaDoc.class, true);
825         infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean JavaDoc.class, true);
826         infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer JavaDoc.class, true);
827
828         infoFactory.addAttribute(GBEAN_SUBMITTER, String JavaDoc.class, true);
829         infoFactory.addAttribute(GBEAN_DSN_NOTIFY, String JavaDoc.class, true);
830         infoFactory.addAttribute(GBEAN_DSN_RET, String JavaDoc.class, true);
831         infoFactory.addAttribute(GBEAN_8BITMIME, Boolean JavaDoc.class, true);
832         infoFactory.addAttribute(GBEAN_SEND_PARTIAL, Boolean JavaDoc.class, true);
833         infoFactory.addAttribute(GBEAN_REPORT_SUCCESS, Boolean JavaDoc.class, true);
834         infoFactory.addAttribute(GBEAN_MAIL_EXTENSION, String JavaDoc.class, true);
835
836         infoFactory.addAttribute(GBEAN_OBJECTNAME, String JavaDoc.class, false);
837         infoFactory.addAttribute(GBEAN_PROTOCOL, String JavaDoc.class, true);
838         infoFactory.addAttribute(GBEAN_PROPERTIES, Properties JavaDoc.class, true);
839         infoFactory.addAttribute(GBEAN_HOST, String JavaDoc.class, true);
840         infoFactory.addAttribute(GBEAN_USER, String JavaDoc.class, true);
841         infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class JavaDoc[]{Properties JavaDoc.class});
842
843         infoFactory.setConstructor(new String JavaDoc[]{GBEAN_OBJECTNAME, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER,
844                                                 GBEAN_PORT,
845                                                 GBEAN_CONNECTION_TIMEOUT,
846                                                 GBEAN_TIMEOUT,
847                                                 GBEAN_FROM,
848                                                 GBEAN_LOCALHOST,
849                                                 GBEAN_LOCALADDRESS,
850                                                 GBEAN_LOCALPORT,
851                                                 GBEAN_EHLO,
852                                                 GBEAN_AUTH,
853                                                 GBEAN_STARTTLS_ENABLE,
854                                                 GBEAN_SUBMITTER,
855                                                 GBEAN_DSN_NOTIFY,
856                                                 GBEAN_DSN_RET,
857                                                 GBEAN_8BITMIME,
858                                                 GBEAN_SEND_PARTIAL,
859                                                 GBEAN_REALM,
860                                                 GBEAN_QUITWAIT,
861                                                 GBEAN_REPORT_SUCCESS,
862                                                 GBEAN_FACTORY_CLASS,
863                                                 GBEAN_FACTORY_FALLBACK,
864                                                 GBEAN_FACTORY_PORT,
865                                                 GBEAN_MAIL_EXTENSION});
866
867         GBEAN_INFO = infoFactory.getBeanInfo();
868     }
869
870     public static GBeanInfo getGBeanInfo() {
871         return GBEAN_INFO;
872     }
873 }
874
Popular Tags