001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.mail;
018    
019    import java.util.Properties;
020    
021    import org.apache.commons.logging.Log;
022    import org.apache.commons.logging.LogFactory;
023    
024    import org.apache.geronimo.gbean.GBeanInfo;
025    import org.apache.geronimo.gbean.GBeanInfoBuilder;
026    
027    /**
028     * A GBean that provides for the configuration of a JavaMail SMTP transport
029     * protocol.
030     * <p/>
031     * SMTP transport properties that are common to all SMTP transports are
032     * provided via member variables of this class.  Values that are set in the
033     * individual member variables will override any of the corresponding values
034     * that have been set in the properties set.
035     *
036     * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
037     * @see MailGBean
038     */
039    public class SMTPTransportGBean extends ProtocolGBean {
040    
041        // the SMTP configuration property names
042        static public final String SMTP_PORT = "mail.smtp.port";
043        static public final String SMTP_CONNECTION_TIMEOUT = "mail.smtp.connectiontimeout";
044        static public final String SMTP_TIMEOUT = "mail.smtp.timeout";
045        static public final String SMTP_FROM = "mail.smtp.from";
046        static public final String SMTP_AUTH = "mail.smtp.auth";
047        static public final String SMTP_REALM = "mail.smtp.sasl.realm";
048        static public final String SMTP_QUITWAIT = "mail.smtp.quitwait";
049        static public final String SMTP_FACTORY_CLASS = "mail.smtp.socketFactory.class";
050        static public final String SMTP_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
051        static public final String SMTP_FACTORY_PORT = "mail.smtp.socketFactory.port";
052        static public final String SMTP_LOCALHOST = "mail.smtp.localhost";
053        static public final String SMTP_LOCALADDRESS = "mail.smtp.localaddress";
054        static public final String SMTP_LOCALPORT = "mail.smtp.localport";
055        static public final String SMTP_EHLO = "mail.smtp.ehlo";
056        static public final String SMTP_SUBMITTER = "mail.smtp.submitter";
057        static public final String SMTP_DSN_NOTIFY = "mail.smtp.dsn.notify";
058        static public final String SMTP_DSN_RET = "mail.smtp.dsn.ret";
059        static public final String SMTP_8BITMIME = "mail.smtp.allow8bitmime";
060        static public final String SMTP_SEND_PARTIAL = "mail.smtp.sendpartial";
061        static public final String SMTP_REPORT_SUCCESS = "mail.smtp.reportsuccess";
062        static public final String SMTP_MAIL_EXTENSION = "mail.smtp.mailextension";
063        static public final String SMTP_STARTTLS_ENABLE = "mail.smtp.starttls.enable";
064    
065        static public final String GBEAN_EHLO = "ehlo";
066        static public final String GBEAN_SUBMITTER = "submitter";
067        static public final String GBEAN_DSN_NOTIFY = "dsnNotify";
068        static public final String GBEAN_DSN_RET = "dsnRet";
069        static public final String GBEAN_8BITMIME = "allow8bitmime";
070        static public final String GBEAN_SEND_PARTIAL = "sendPartical";
071        static public final String GBEAN_REPORT_SUCCESS = "reportSuccess";
072        static public final String GBEAN_MAIL_EXTENSION = "mailExtension";
073    static public final String GBEAN_STARTTLS_ENABLE = "startTLSEnable";
074    
075    
076        private final Log log = LogFactory.getLog(SMTPTransportGBean.class);
077    
078        private Integer port;
079        private Integer connectionTimeout;
080        private Integer timeout;
081        private String from;
082        private String localhost;
083        private String localaddress;
084        private Integer localport;
085        private Boolean ehlo;
086        private Boolean auth;
087        private String submitter;
088        private String dsnNotify;
089        private String dsnRet;
090        private Boolean allow8bitmime;
091        private Boolean sendPartial;
092        private String saslRealm;
093        private Boolean quitWait;
094        private Boolean reportSuccess;
095        private String socketFactoryClass;
096        private Boolean socketFactoryFallback;
097        private Integer socketFactoryPort;
098        private String mailExtension;
099        private Boolean 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 objectName, Properties properties, String host, String user,
141                                  Integer port,
142                                  Integer connectionTimeout,
143                                  Integer timeout,
144                                  String from,
145                                  String localhost,
146                                  String localaddress,
147                                  Integer localport,
148                                  Boolean ehlo,
149                                  Boolean auth,
150                                  Boolean startTLSEnable,
151                                  String submitter,
152                                  String dsnNotify,
153                                  String dsnRet,
154                                  Boolean allow8bitmime,
155                                  Boolean sendPartial,
156                                  String saslRealm,
157                                  Boolean quitWait,
158                                  Boolean reportSuccess,
159                                  String socketFactoryClass,
160                                  Boolean socketFactoryFallback,
161                                  Integer socketFactoryPort,
162                                  String 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 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 port) {
209            this.port = port;
210        }
211    
212        /**
213         * Returns the socket connection timeout value in milliseconds.
214         */
215        public Integer 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 connectionTimeout) {
230            this.connectionTimeout = connectionTimeout;
231        }
232    
233        /**
234         * Returns the socket I/O timeout value in milliseconds.
235         */
236        public Integer 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 timeout) {
251            this.timeout = timeout;
252        }
253    
254        /**
255         * Returns the email address to use for SMTP MAIL command.
256         */
257        public String 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 sendPartial) {
571            this.sendPartial = sendPartial;
572        }
573    
574        /**
575         * Returns the realm to use with DIGEST-MD5 authentication.
576         */
577        public String 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 {
796            log.debug("Started " + getObjectName());
797        }
798    
799        public void doStop() throws Exception {
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.class, true);
813            infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer.class, true);
814            infoFactory.addAttribute(GBEAN_TIMEOUT, Integer.class, true);
815            infoFactory.addAttribute(GBEAN_AUTH, Boolean.class, true);
816            infoFactory.addAttribute(GBEAN_STARTTLS_ENABLE, Boolean.class, true);
817            infoFactory.addAttribute(GBEAN_EHLO, Boolean.class, true);
818            infoFactory.addAttribute(GBEAN_FROM, String.class, true);
819            infoFactory.addAttribute(GBEAN_LOCALHOST, String.class, true);
820            infoFactory.addAttribute(GBEAN_LOCALADDRESS, String.class, true);
821            infoFactory.addAttribute(GBEAN_LOCALPORT, Integer.class, true);
822            infoFactory.addAttribute(GBEAN_REALM, String.class, true);
823            infoFactory.addAttribute(GBEAN_QUITWAIT, Boolean.class, true);
824            infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String.class, true);
825            infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean.class, true);
826            infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer.class, true);
827    
828            infoFactory.addAttribute(GBEAN_SUBMITTER, String.class, true);
829            infoFactory.addAttribute(GBEAN_DSN_NOTIFY, String.class, true);
830            infoFactory.addAttribute(GBEAN_DSN_RET, String.class, true);
831            infoFactory.addAttribute(GBEAN_8BITMIME, Boolean.class, true);
832            infoFactory.addAttribute(GBEAN_SEND_PARTIAL, Boolean.class, true);
833            infoFactory.addAttribute(GBEAN_REPORT_SUCCESS, Boolean.class, true);
834            infoFactory.addAttribute(GBEAN_MAIL_EXTENSION, String.class, true);
835    
836            infoFactory.addAttribute(GBEAN_OBJECTNAME, String.class, false);
837            infoFactory.addAttribute(GBEAN_PROTOCOL, String.class, true);
838            infoFactory.addAttribute(GBEAN_PROPERTIES, Properties.class, true);
839            infoFactory.addAttribute(GBEAN_HOST, String.class, true);
840            infoFactory.addAttribute(GBEAN_USER, String.class, true);
841            infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class[]{Properties.class});
842    
843            infoFactory.setConstructor(new String[]{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    }