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