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 SMTPSTransportGBean extends ProtocolGBean {
040    
041        // the SMTPS configuration property names
042        static public final String SMTPS_PORT = "mail.smtp.port";
043        static public final String SMTPS_CONNECTION_TIMEOUT = "mail.smtp.connectiontimeout";
044        static public final String SMTPS_TIMEOUT = "mail.smtp.timeout";
045        static public final String SMTPS_FROM = "mail.smtp.from";
046        static public final String SMTPS_AUTH = "mail.smtp.auth";
047        static public final String SMTPS_REALM = "mail.smtp.sasl.realm";
048        static public final String SMTPS_QUITWAIT = "mail.smtp.quitwait";
049        static public final String SMTPS_FACTORY_CLASS = "mail.smtp.socketFactory.class";
050        static public final String SMTPS_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
051        static public final String SMTPS_FACTORY_PORT = "mail.smtp.socketFactory.port";
052        static public final String SMTPS_LOCALHOST = "mail.smtp.localhost";
053        static public final String SMTPS_LOCALADDRESS = "mail.smtp.localaddress";
054        static public final String SMTPS_LOCALPORT = "mail.smtp.localport";
055        static public final String SMTPS_EHLO = "mail.smtp.ehlo";
056        static public final String SMTPS_SUBMITTER = "mail.smtp.submitter";
057        static public final String SMTPS_DSN_NOTIFY = "mail.smtp.dsn.notify";
058        static public final String SMTPS_DSN_RET = "mail.smtp.dsn.ret";
059        static public final String SMTPS_8BITMIME = "mail.smtp.allow8bitmime";
060        static public final String SMTPS_SEND_PARTIAL = "mail.smtp.sendpartial";
061        static public final String SMTPS_REPORT_SUCCESS = "mail.smtp.reportsuccess";
062        static public final String SMTPS_MAIL_EXTENSION = "mail.smtp.mailextension";
063        static public final String SMTPS_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        private final Log log = LogFactory.getLog(SMTPSTransportGBean.class);
076    
077        private Integer port;
078        private Integer connectionTimeout;
079        private Integer timeout;
080        private String from;
081        private String localhost;
082        private String localaddress;
083        private Integer localport;
084        private Boolean ehlo;
085        private Boolean auth;
086        private String submitter;
087        private String dsnNotify;
088        private String dsnRet;
089        private Boolean allow8bitmime;
090        private Boolean sendPartial;
091        private String saslRealm;
092        private Boolean quitWait;
093        private Boolean reportSuccess;
094        private String socketFactoryClass;
095        private Boolean socketFactoryFallback;
096        private Integer socketFactoryPort;
097        private String mailExtension;
098        private Boolean startTLSEnable;
099    
100    
101        /**
102         * Construct an instance of SMTPSTransportGBean
103         * <p/>
104         * Values that are set in the individual member variables will override any of
105         * the corresponding values that have been set in the properties set.
106         *
107         * @param objectName            the object name of the protocol
108         * @param properties            the set of default properties for the protocol
109         * @param host                  the host the protocol connects to
110         * @param user                  the default name for the protocol
111         * @param port                  the SMTPS server port
112         * @param connectionTimeout     the socket connection timeout value in milliseconds
113         * @param timeout               the socket I/O timeout value in milliseconds
114         * @param from                  the email address to use for SMTPS MAIL command
115         * @param localhost             the local host name used in the SMTPS HELO or EHLO command
116         * @param localaddress          the local address (host name) to bind to when creating the SMTPS socket
117         * @param localport             the local port number to bind to when creating the SMTPS socket
118         * @param ehlo                  whether an attempt will be made to sign on with the EHLO command
119         * @param auth                  whether an attempt will be made to authenticate the user using
120         *                              the AUTH command
121         * @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
122         * @param submitter             the submitter to use in the AUTH tag in the MAIL FROM command
123         * @param dsnNotify             the NOTIFY option to the RCPT command
124         * @param dsnRet                the RET option to the MAIL command
125         * @param allow8bitmime         whether encodings are converted to use "8bit" under certain
126         *                              conditions
127         * @param sendPartial           whether to send email to valid addresses when others are invalid
128         * @param saslRealm             the realm to use with DIGEST-MD5 authentication
129         * @param quitWait              whether the transport will wait for the response to the QUIT command
130         * @param reportSuccess         whether the transport will include an SMTPAddressSucceededException
131         *                              for each address that is successful
132         * @param socketFactoryClass    the class that will be used to create SMTPS sockets
133         * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
134         *                              socket factory class cannot be created
135         * @param socketFactoryPort     whether java.net.Socket class will be created if the specified
136         *                              socket factory class cannot be created
137         * @param mailExtension         the extension string to append to the MAIL command
138         */
139        public SMTPSTransportGBean(String objectName, Properties properties, String host, String user,
140                                  Integer port,
141                                  Integer connectionTimeout,
142                                  Integer timeout,
143                                  String from,
144                                  String localhost,
145                                  String localaddress,
146                                  Integer localport,
147                                  Boolean ehlo,
148                                  Boolean auth,
149                                  Boolean startTLSEnable,
150                                  String submitter,
151                                  String dsnNotify,
152                                  String dsnRet,
153                                  Boolean allow8bitmime,
154                                  Boolean sendPartial,
155                                  String saslRealm,
156                                  Boolean quitWait,
157                                  Boolean reportSuccess,
158                                  String socketFactoryClass,
159                                  Boolean socketFactoryFallback,
160                                  Integer socketFactoryPort,
161                                  String mailExtension) {
162            super(objectName, "smtps", properties, host, user);
163    
164            setPort(port);
165            setConnectionTimeout(connectionTimeout);
166            setTimeout(timeout);
167            setFrom(from);
168            setLocalhost(localhost);
169            setLocaladdress(localaddress);
170            setLocalport(localport);
171            setEhlo(ehlo);
172            setAuth(auth);
173            setStartTLSEnable(startTLSEnable);
174            setSubmitter(submitter);
175            setDsnNotify(dsnNotify);
176            setDsnRet(dsnRet);
177            setAllow8bitmime(allow8bitmime);
178            setSendPartial(sendPartial);
179            setSaslRealm(saslRealm);
180            setQuitWait(quitWait);
181            setReportSuccess(reportSuccess);
182            setSocketFactoryClass(socketFactoryClass);
183            setSocketFactoryFallback(socketFactoryFallback);
184            setSocketFactoryPort(socketFactoryPort);
185            setMailExtension(mailExtension);
186        }
187    
188        /**
189         * Returns the SMTP server port to connect to, if the connect() method
190         * doesn't explicitly specify one.
191         */
192        public Integer getPort() {
193            return port;
194        }
195    
196        /**
197         * Sets the SMTP server port to connect to, if the connect() method
198         * doesn't explicitly specify one.
199         * <p/>
200         * Defaults to 25.
201         * <p/>
202         * Values that are set here will override any of the corresponding value
203         * that has been set in the properties.
204         *
205         * @param port the SMTP server port to connect to
206         */
207        public void setPort(Integer port) {
208            this.port = port;
209        }
210    
211        /**
212         * Returns the socket connection timeout value in milliseconds.
213         */
214        public Integer getConnectionTimeout() {
215            return connectionTimeout;
216        }
217    
218        /**
219         * Sets the socket connection timeout value in milliseconds.
220         * <p/>
221         * Default is infinite timeout.
222         * <p/>
223         * Values that are set here will override any of the corresponding value
224         * that has been set in the properties.
225         *
226         * @param connectionTimeout the socket connection timeout value in milliseconds.
227         */
228        public void setConnectionTimeout(Integer connectionTimeout) {
229            this.connectionTimeout = connectionTimeout;
230        }
231    
232        /**
233         * Returns the socket I/O timeout value in milliseconds.
234         */
235        public Integer getTimeout() {
236            return timeout;
237        }
238    
239        /**
240         * Sets the socket I/O timeout value in milliseconds.
241         * <p/>
242         * Default is infinite timeout.
243         * <p/>
244         * Values that are set here will override any of the corresponding value
245         * that has been set in the properties.
246         *
247         * @param timeout the socket I/O timeout value in milliseconds
248         */
249        public void setTimeout(Integer timeout) {
250            this.timeout = timeout;
251        }
252    
253        /**
254         * Returns the email address to use for SMTP MAIL command.
255         */
256        public String getFrom() {
257            return from;
258        }
259    
260        /**
261         * Sets the email address to use for SMTP MAIL command
262         * <p/>
263         * Email address to use for SMTP MAIL command. This sets the envelope
264         * return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress().
265         * NOTE: mail.smtp.user was previously used for this.
266         * <p/>
267         * Values that are set here will override any of the corresponding value
268         * that has been set in the properties.
269         *
270         * @param from the email address to use for SMTP MAIL command
271         */
272        public void setFrom(String from) {
273            this.from = from;
274        }
275    
276        /**
277         * Returns the local host name used in the SMTP HELO or EHLO command.
278         */
279        public String getLocalhost() {
280            return localhost;
281        }
282    
283        /**
284         * Sets the local host name used in the SMTP HELO or EHLO command.
285         * <p/>
286         * Local host name used in the SMTP HELO or EHLO command. Defaults to
287         * InetAddress.getLocalHost().getHostName(). Should not normally need to
288         * be set if your JDK and your name service are configured properly.
289         * <p/>
290         * Values that are set here will override any of the corresponding value
291         * that has been set in the properties.
292         *
293         * @param localhost the local host name used in the SMTP HELO or EHLO command
294         */
295        public void setLocalhost(String localhost) {
296            this.localhost = localhost;
297        }
298    
299        /**
300         * Returns the local address (host name) to bind to when creating the SMTP socket.
301         */
302        public String getLocaladdress() {
303            return localaddress;
304        }
305    
306        /**
307         * Sets the local address (host name) to bind to when creating the SMTP socket.
308         * <p/>
309         * Local address (host name) to bind to when creating the SMTP socket.
310         * Defaults to the address picked by the Socket class. Should not normally
311         * need to be set, but useful with multi-homed hosts where it's important
312         * to pick a particular local address to bind to.
313         * <p/>
314         * Values that are set here will override any of the corresponding value
315         * that has been set in the properties.
316         *
317         * @param localaddress the local address (host name) to bind to when creating the SMTP socket
318         */
319        public void setLocaladdress(String localaddress) {
320            this.localaddress = localaddress;
321        }
322    
323        /**
324         * Returns the local port number to bind to when creating the SMTP socket.
325         */
326        public Integer getLocalport() {
327            return localport;
328        }
329    
330        /**
331         * Sets the local port number to bind to when creating the SMTP socket.
332         * <p/>
333         * Local port number to bind to when creating the SMTP socket. Defaults to
334         * the port number picked by the Socket class.
335         * <p/>
336         * Values that are set here will override any of the corresponding value
337         * that has been set in the properties.
338         *
339         * @param localport the local port number to bind to when creating the SMTP socket
340         */
341        public void setLocalport(Integer localport) {
342            this.localport = localport;
343        }
344    
345        /**
346         * Returns whether an attempt will be made to sign on with the EHLO command.
347         * <p/>
348         * If false, do not attempt to sign on with the EHLO command. Normally
349         * failure of the EHLO command will fallback to the HELO command; this
350         * property exists only for servers that don't fail EHLO properly or don't
351         * implement EHLO properly.
352         */
353        public Boolean getEhlo() {
354            return ehlo;
355        }
356    
357        /**
358         * Set whether an attempt will be made to sign on with the EHLO command.
359         * <p/>
360         * If false, do not attempt to sign on with the EHLO command. Normally
361         * failure of the EHLO command will fallback to the HELO command; this
362         * property exists only for servers that don't fail EHLO properly or don't
363         * implement EHLO properly.
364         * <p/>
365         * Values that are set here will override any of the corresponding value
366         * that has been set in the properties.
367         *
368         * @param ehlo whether an attempt will be made to sign on with the EHLO command
369         */
370        public void setEhlo(Boolean ehlo) {
371            this.ehlo = ehlo;
372        }
373    
374        /**
375         * Returns whether an attempt will be made to authenticate the user using
376         * the AUTH command.
377         * <p/>
378         * Defaults to false.
379         */
380        public Boolean getAuth() {
381            return auth;
382        }
383    
384        /**
385         * Sets whether an attempt will be made to authenticate the user using
386         * the AUTH command.
387         * <p/>
388         * Defaults to false.
389         * <p/>
390         * Values that are set here will override any of the corresponding value
391         * that has been set in the properties.
392         *
393         * @param auth whether an attempt will be made to authenticate the user using
394         *             the AUTH command.
395         */
396        public void setAuth(Boolean auth) {
397            this.auth = auth;
398        }
399    
400        /**
401         * Returns the flag that enables the use of the STARTTLS command (if
402         * supported by the server) to switch the connection to a TLS-protected
403         * connection before issuing any login commands.
404         * <p/>
405         * If true, enables the use of the STARTTLS command (if supported by the
406         * server) to switch the connection to a TLS-protected connection before
407         * issuing any login commands. Note that an appropriate trust store must
408         * configured so that the client will trust the server's certificate.
409         * This feature only works on J2SE 1.4 and newer systems. Default is false.
410         */
411        public Boolean getStartTLSEnable() {
412            return startTLSEnable;
413        }
414    
415        /**
416         * Sets the flag that enables the use of the STARTTLS command (if
417         * supported by the server) to switch the connection to a TLS-protected
418         * connection before issuing any login commands.
419         * <p/>
420         * If true, enables the use of the STARTTLS command (if supported by the
421         * server) to switch the connection to a TLS-protected connection before
422         * issuing any login commands. Note that an appropriate trust store must
423         * configured so that the client will trust the server's certificate.
424         * This feature only works on J2SE 1.4 and newer systems. Default is false.
425         * <p/>
426         * Values that are set here will override any of the corresponding value
427         * that has been set in the properties.
428         *
429         * @param startTLSEnable the flag that enables the use of the STARTTLS command (if
430         *                       supported by the server) to switch the connection to a TLS-protected
431         *                       connection before issuing any login commands
432         */
433        public void setStartTLSEnable(Boolean startTLSEnable) {
434            this.startTLSEnable = startTLSEnable;
435        }
436    
437        /**
438         * Returns the submitter to use in the AUTH tag in the MAIL FROM command.
439         * <p/>
440         * Typically used by a mail relay to pass along information about the
441         * original submitter of the message. See also the setSubmitter method of
442         * SMTPMessage. Mail clients typically do not use this.
443         */
444        public String getSubmitter() {
445            return submitter;
446        }
447    
448        /**
449         * Sets the submitter to use in the AUTH tag in the MAIL FROM command.
450         * <p/>
451         * Typically used by a mail relay to pass along information about the
452         * original submitter of the message. See also the setSubmitter method of
453         * SMTPMessage. Mail clients typically do not use this.
454         * <p/>
455         * Values that are set here will override any of the corresponding value
456         * that has been set in the properties.
457         *
458         * @param submitter the submitter to use in the AUTH tag in the MAIL FROM command
459         */
460        public void setSubmitter(String submitter) {
461            this.submitter = submitter;
462        }
463    
464        /**
465         * Returns the NOTIFY option to the RCPT command.
466         * <p/>
467         * Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY
468         * (separated by commas).
469         */
470        public String getDsnNotify() {
471            return dsnNotify;
472        }
473    
474        /**
475         * Sets the NOTIFY option to the RCPT command
476         * <p/>
477         * Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY
478         * (separated by commas).
479         * <p/>
480         * Values that are set here will override any of the corresponding value
481         * that has been set in the properties.
482         *
483         * @param dsnNotify the NOTIFY option to the RCPT command
484         */
485        public void setDsnNotify(String dsnNotify) {
486            this.dsnNotify = dsnNotify;
487        }
488    
489        /**
490         * Returns the RET option to the MAIL command.
491         * <p/>
492         * Either FULL or HDRS.
493         */
494        public String getDsnRet() {
495            return dsnRet;
496        }
497    
498        /**
499         * Sets the RET option to the MAIL command
500         * <p/>
501         * Either FULL or HDRS.
502         * <p/>
503         * Values that are set here will override any of the corresponding value
504         * that has been set in the properties.
505         *
506         * @param dsnRet the RET option to the MAIL command
507         */
508        public void setDsnRet(String dsnRet) {
509            this.dsnRet = dsnRet;
510        }
511    
512        /**
513         * Returns whether encodings are converted to use "8bit" under certain
514         * conditions.
515         * <p/>
516         * If set to true, and the server supports the 8BITMIME extension, text
517         * parts of messages that use the "quoted-printable" or "base64" encodings
518         * are converted to use "8bit" encoding if they follow the RFC2045 rules
519         * for 8bit text.
520         */
521        public Boolean getAllow8bitmime() {
522            return allow8bitmime;
523        }
524    
525        /**
526         * Sets whether encodings are converted to use "8bit" under certain
527         * conditions.
528         * <p/>
529         * If set to true, and the server supports the 8BITMIME extension, text
530         * parts of messages that use the "quoted-printable" or "base64" encodings
531         * are converted to use "8bit" encoding if they follow the RFC2045 rules
532         * for 8bit text.
533         * <p/>
534         * Values that are set here will override any of the corresponding value
535         * that has been set in the properties.
536         *
537         * @param allow8bitmime whether encodings are converted to use "8bit" under certain
538         *                      conditions
539         */
540        public void setAllow8bitmime(Boolean allow8bitmime) {
541            this.allow8bitmime = allow8bitmime;
542        }
543    
544        /**
545         * Returns whether to send email to valid addresses when others are invalid.
546         * <p/>
547         * If set to true, and a message has some valid and some invalid addresses,
548         * send the message anyway, reporting the partial failure with a
549         * SendFailedException. If set to false (the default), the message is not
550         * sent to any of the recipients if there is an invalid recipient address.
551         */
552        public Boolean getSendPartial() {
553            return sendPartial;
554        }
555    
556        /**
557         * Sets whether to send email to valid addresses when others are invalid.
558         * <p/>
559         * If set to true, and a message has some valid and some invalid addresses,
560         * send the message anyway, reporting the partial failure with a
561         * SendFailedException. If set to false (the default), the message is not
562         * sent to any of the recipients if there is an invalid recipient address.
563         * <p/>
564         * Values that are set here will override any of the corresponding value
565         * that has been set in the properties.
566         *
567         * @param sendPartial whether to send email to valid addresses when others are invalid
568         */
569        public void setSendPartial(Boolean sendPartial) {
570            this.sendPartial = sendPartial;
571        }
572    
573        /**
574         * Returns the realm to use with DIGEST-MD5 authentication.
575         */
576        public String getSaslRealm() {
577            return saslRealm;
578        }
579    
580        /**
581         * Sets the realm to use with DIGEST-MD5 authentication.
582         * <p/>
583         * Values that are set here will override any of the corresponding value
584         * that has been set in the properties.
585         *
586         * @param saslRealm the realm to use with DIGEST-MD5 authentication
587         */
588        public void setSaslRealm(String saslRealm) {
589            this.saslRealm = saslRealm;
590        }
591    
592        /**
593         * Returns whether the transport will wait for the response to the QUIT command.
594         * <p/>
595         * If set to true, causes the transport to wait for the response to the QUIT
596         * command. If set to false (the default), the QUIT command is sent and the
597         * connection is immediately closed.
598         */
599        public Boolean getQuitWait() {
600            return quitWait;
601        }
602    
603        /**
604         * Sets whether the transport will wait for the response to the QUIT command
605         * <p/>
606         * If set to true, causes the transport to wait for the response to the QUIT
607         * command. If set to false (the default), the QUIT command is sent and the
608         * connection is immediately closed.
609         * <p/>
610         * Values that are set here will override any of the corresponding value
611         * that has been set in the properties.
612         *
613         * @param quitWait whether the transport will wait for the response to the QUIT command
614         */
615        public void setQuitWait(Boolean quitWait) {
616            this.quitWait = quitWait;
617        }
618    
619        /**
620         * Returns whether the transport will include an SMTPAddressSucceededException
621         * for each address that is successful.
622         * <p/>
623         * Note also that this will cause a SendFailedException to be thrown from
624         * the sendMessage method of SMTPTransport even if all addresses were
625         * correct and the message was sent successfully.
626         */
627        public Boolean getReportSuccess() {
628            return reportSuccess;
629        }
630    
631        /**
632         * Sets whether the transport will include an SMTPAddressSucceededException
633         * for each address that is successful.
634         * <p/>
635         * Note also that this will cause a SendFailedException to be thrown from
636         * the sendMessage method of SMTPTransport even if all addresses were
637         * correct and the message was sent successfully.
638         * <p/>
639         * Values that are set here will override any of the corresponding value
640         * that has been set in the properties.
641         *
642         * @param reportSuccess whether the transport will include an SMTPAddressSucceededException
643         *                      for each address that is successful
644         */
645        public void setReportSuccess(Boolean reportSuccess) {
646            this.reportSuccess = reportSuccess;
647        }
648    
649        /**
650         * Returns the class that will be used to create SMTP sockets.
651         * <p/>
652         * If set, specifies the name of a class that implements the
653         * javax.net.SocketFactory interface. This class will be used to create SMTP
654         * sockets.
655         */
656        public String getSocketFactoryClass() {
657            return socketFactoryClass;
658        }
659    
660        /**
661         * Sets the class that will be used to create SMTP sockets.
662         * <p/>
663         * If set, specifies the name of a class that implements the
664         * javax.net.SocketFactory interface. This class will be used to create SMTP
665         * sockets.
666         * <p/>
667         * Values that are set here will override any of the corresponding value
668         * that has been set in the properties.
669         *
670         * @param socketFactoryClass the class that will be used to create SMTP sockets
671         */
672        public void setSocketFactoryClass(String socketFactoryClass) {
673            this.socketFactoryClass = socketFactoryClass;
674        }
675    
676        /**
677         * Returns whether java.net.Socket class will be created if the specified
678         * socket factory class cannot be created.
679         * <p/>
680         * If set to true, failure to create a socket using the specified socket
681         * factory class will cause the socket to be created using the
682         * java.net.Socket class. Defaults to true.
683         */
684        public Boolean getSocketFactoryFallback() {
685            return socketFactoryFallback;
686        }
687    
688        /**
689         * Sets whether java.net.Socket class will be created if the specified
690         * socket factory class cannot be created.
691         * <p/>
692         * If set to true, failure to create a socket using the specified socket
693         * factory class will cause the socket to be created using the
694         * java.net.Socket class. Defaults to true.
695         * <p/>
696         * Values that are set here will override any of the corresponding value
697         * that has been set in the properties.
698         *
699         * @param socketFactoryFallback whether java.net.Socket class will be created if the specified
700         *                              socket factory class cannot be created
701         */
702        public void setSocketFactoryFallback(Boolean socketFactoryFallback) {
703            this.socketFactoryFallback = socketFactoryFallback;
704        }
705    
706        /**
707         * Returns the port to connect to when using the specified socket factory.
708         * <p/>
709         * Specifies the port to connect to when using the specified socket
710         * factory. If not set, the default port will be used.
711         */
712        public Integer getSocketFactoryPort() {
713            return socketFactoryPort;
714        }
715    
716        /**
717         * Sets the port to connect to when using the specified socket factory.
718         * <p/>
719         * Specifies the port to connect to when using the specified socket
720         * factory. If not set, the default port will be used.
721         * <p/>
722         * Values that are set here will override any of the corresponding value
723         * that has been set in the properties.
724         *
725         * @param socketFactoryPort the port to connect to when using the specified socket factory
726         */
727        public void setSocketFactoryPort(Integer socketFactoryPort) {
728            this.socketFactoryPort = socketFactoryPort;
729        }
730    
731        /**
732         * Returns the extension string to append to the MAIL command.
733         * <p/>
734         * Extension string to append to the MAIL command. The extension string
735         * can be used to specify standard SMTP service extensions as well as
736         * vendor-specific extensions. Typically the application should use the
737         * SMTPTransport method supportsExtension to verify that the server
738         * supports the desired service extension. See RFC 1869 and other RFCs
739         * that define specific extensions.
740         */
741        public String getMailExtension() {
742            return mailExtension;
743        }
744    
745        /**
746         * Sets the extension string to append to the MAIL command.
747         * <p/>
748         * Extension string to append to the MAIL command. The extension string
749         * can be used to specify standard SMTP service extensions as well as
750         * vendor-specific extensions. Typically the application should use the
751         * SMTPTransport method supportsExtension to verify that the server
752         * supports the desired service extension. See RFC 1869 and other RFCs
753         * that define specific extensions.
754         * <p/>
755         * Values that are set here will override any of the corresponding value
756         * that has been set in the properties.
757         *
758         * @param mailExtension the extension string to append to the MAIL command
759         */
760        public void setMailExtension(String mailExtension) {
761            this.mailExtension = mailExtension;
762        }
763    
764        /**
765         * Add the overrides from the member variables to the properties file.
766         */
767        public void addOverrides(Properties props) {
768            super.addOverrides(props);
769    
770            if (port != null) props.setProperty(SMTPS_PORT, port.toString());
771            if (connectionTimeout != null) props.setProperty(SMTPS_CONNECTION_TIMEOUT, connectionTimeout.toString());
772            if (timeout != null) props.setProperty(SMTPS_TIMEOUT, timeout.toString());
773            if (from != null) props.setProperty(SMTPS_FROM, from);
774            if (localhost != null) props.setProperty(SMTPS_LOCALHOST, localhost);
775            if (localaddress != null) props.setProperty(SMTPS_LOCALADDRESS, localaddress);
776            if (localport != null) props.setProperty(SMTPS_LOCALPORT, localport.toString());
777            if (ehlo != null) props.setProperty(SMTPS_EHLO, ehlo.toString());
778            if (auth != null) props.setProperty(SMTPS_AUTH, auth.toString());
779            if (startTLSEnable != null) props.setProperty(SMTPS_STARTTLS_ENABLE, startTLSEnable.toString());
780            if (submitter != null) props.setProperty(SMTPS_SUBMITTER, submitter);
781            if (dsnNotify != null) props.setProperty(SMTPS_DSN_NOTIFY, dsnNotify.toString());
782            if (dsnRet != null) props.setProperty(SMTPS_DSN_RET, dsnRet.toString());
783            if (allow8bitmime != null) props.setProperty(SMTPS_8BITMIME, allow8bitmime.toString());
784            if (sendPartial != null) props.setProperty(SMTPS_SEND_PARTIAL, sendPartial.toString());
785            if (saslRealm != null) props.setProperty(SMTPS_REALM, saslRealm);
786            if (quitWait != null) props.setProperty(SMTPS_QUITWAIT, quitWait.toString());
787            if (reportSuccess != null) props.setProperty(SMTPS_REPORT_SUCCESS, reportSuccess.toString());
788            if (socketFactoryClass != null) props.setProperty(SMTPS_FACTORY_CLASS, socketFactoryClass);
789            if (socketFactoryFallback != null) props.setProperty(SMTPS_FACTORY_FALLBACK, socketFactoryFallback.toString());
790            if (socketFactoryPort != null) props.setProperty(SMTPS_FACTORY_PORT, socketFactoryPort.toString());
791            if (mailExtension != null) props.setProperty(SMTPS_MAIL_EXTENSION, mailExtension);
792        }
793    
794        public void doStart() throws Exception {
795            log.debug("Started " + getObjectName());
796        }
797    
798        public void doStop() throws Exception {
799            log.debug("Stopped " + getObjectName());
800        }
801    
802        public void doFail() {
803            log.warn("Failed " + getObjectName());
804        }
805    
806        public static final GBeanInfo GBEAN_INFO;
807    
808        static {
809            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(SMTPSTransportGBean.class);
810    
811            infoFactory.addAttribute(GBEAN_PORT, Integer.class, true);
812            infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer.class, true);
813            infoFactory.addAttribute(GBEAN_TIMEOUT, Integer.class, true);
814            infoFactory.addAttribute(GBEAN_AUTH, Boolean.class, true);
815            infoFactory.addAttribute(GBEAN_STARTTLS_ENABLE, Boolean.class, true);
816            infoFactory.addAttribute(GBEAN_EHLO, Boolean.class, true);
817            infoFactory.addAttribute(GBEAN_FROM, String.class, true);
818            infoFactory.addAttribute(GBEAN_LOCALHOST, String.class, true);
819            infoFactory.addAttribute(GBEAN_LOCALADDRESS, String.class, true);
820            infoFactory.addAttribute(GBEAN_LOCALPORT, Integer.class, true);
821            infoFactory.addAttribute(GBEAN_REALM, String.class, true);
822            infoFactory.addAttribute(GBEAN_QUITWAIT, Boolean.class, true);
823            infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String.class, true);
824            infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean.class, true);
825            infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer.class, true);
826    
827            infoFactory.addAttribute(GBEAN_SUBMITTER, String.class, true);
828            infoFactory.addAttribute(GBEAN_DSN_NOTIFY, String.class, true);
829            infoFactory.addAttribute(GBEAN_DSN_RET, String.class, true);
830            infoFactory.addAttribute(GBEAN_8BITMIME, Boolean.class, true);
831            infoFactory.addAttribute(GBEAN_SEND_PARTIAL, Boolean.class, true);
832            infoFactory.addAttribute(GBEAN_REPORT_SUCCESS, Boolean.class, true);
833            infoFactory.addAttribute(GBEAN_MAIL_EXTENSION, String.class, true);
834    
835            infoFactory.addAttribute(GBEAN_OBJECTNAME, String.class, false);
836            infoFactory.addAttribute(GBEAN_PROTOCOL, String.class, true);
837            infoFactory.addAttribute(GBEAN_PROPERTIES, Properties.class, true);
838            infoFactory.addAttribute(GBEAN_HOST, String.class, true);
839            infoFactory.addAttribute(GBEAN_USER, String.class, true);
840            infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class[]{Properties.class});
841    
842            infoFactory.setConstructor(new String[]{GBEAN_OBJECTNAME, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER,
843                                                    GBEAN_PORT,
844                                                    GBEAN_CONNECTION_TIMEOUT,
845                                                    GBEAN_TIMEOUT,
846                                                    GBEAN_FROM,
847                                                    GBEAN_LOCALHOST,
848                                                    GBEAN_LOCALADDRESS,
849                                                    GBEAN_LOCALPORT,
850                                                    GBEAN_EHLO,
851                                                    GBEAN_AUTH,
852                                                    GBEAN_STARTTLS_ENABLE,
853                                                    GBEAN_SUBMITTER,
854                                                    GBEAN_DSN_NOTIFY,
855                                                    GBEAN_DSN_RET,
856                                                    GBEAN_8BITMIME,
857                                                    GBEAN_SEND_PARTIAL,
858                                                    GBEAN_REALM,
859                                                    GBEAN_QUITWAIT,
860                                                    GBEAN_REPORT_SUCCESS,
861                                                    GBEAN_FACTORY_CLASS,
862                                                    GBEAN_FACTORY_FALLBACK,
863                                                    GBEAN_FACTORY_PORT,
864                                                    GBEAN_MAIL_EXTENSION});
865    
866            GBEAN_INFO = infoFactory.getBeanInfo();
867        }
868    
869        public static GBeanInfo getGBeanInfo() {
870            return GBEAN_INFO;
871        }
872    }
873