1 17 package org.apache.geronimo.mail; 18 19 import java.util.Properties ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 27 39 public class SMTPTransportGBean extends ProtocolGBean { 40 41 static public final String SMTP_PORT = "mail.smtp.port"; 43 static public final String SMTP_CONNECTION_TIMEOUT = "mail.smtp.connectiontimeout"; 44 static public final String SMTP_TIMEOUT = "mail.smtp.timeout"; 45 static public final String SMTP_FROM = "mail.smtp.from"; 46 static public final String SMTP_AUTH = "mail.smtp.auth"; 47 static public final String SMTP_REALM = "mail.smtp.sasl.realm"; 48 static public final String SMTP_QUITWAIT = "mail.smtp.quitwait"; 49 static public final String SMTP_FACTORY_CLASS = "mail.smtp.socketFactory.class"; 50 static public final String SMTP_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback"; 51 static public final String SMTP_FACTORY_PORT = "mail.smtp.socketFactory.port"; 52 static public final String SMTP_LOCALHOST = "mail.smtp.localhost"; 53 static public final String SMTP_LOCALADDRESS = "mail.smtp.localaddress"; 54 static public final String SMTP_LOCALPORT = "mail.smtp.localport"; 55 static public final String SMTP_EHLO = "mail.smtp.ehlo"; 56 static public final String SMTP_SUBMITTER = "mail.smtp.submitter"; 57 static public final String SMTP_DSN_NOTIFY = "mail.smtp.dsn.notify"; 58 static public final String SMTP_DSN_RET = "mail.smtp.dsn.ret"; 59 static public final String SMTP_8BITMIME = "mail.smtp.allow8bitmime"; 60 static public final String SMTP_SEND_PARTIAL = "mail.smtp.sendpartial"; 61 static public final String SMTP_REPORT_SUCCESS = "mail.smtp.reportsuccess"; 62 static public final String SMTP_MAIL_EXTENSION = "mail.smtp.mailextension"; 63 static public final String SMTP_STARTTLS_ENABLE = "mail.smtp.starttls.enable"; 64 65 static public final String GBEAN_EHLO = "ehlo"; 66 static public final String GBEAN_SUBMITTER = "submitter"; 67 static public final String GBEAN_DSN_NOTIFY = "dsnNotify"; 68 static public final String GBEAN_DSN_RET = "dsnRet"; 69 static public final String GBEAN_8BITMIME = "allow8bitmime"; 70 static public final String GBEAN_SEND_PARTIAL = "sendPartical"; 71 static public final String GBEAN_REPORT_SUCCESS = "reportSuccess"; 72 static public final String GBEAN_MAIL_EXTENSION = "mailExtension"; 73 static public final String GBEAN_STARTTLS_ENABLE = "startTLSEnable"; 74 75 76 private final Log log = LogFactory.getLog(SMTPTransportGBean.class); 77 78 private Integer port; 79 private Integer connectionTimeout; 80 private Integer timeout; 81 private String from; 82 private String localhost; 83 private String localaddress; 84 private Integer localport; 85 private Boolean ehlo; 86 private Boolean auth; 87 private String submitter; 88 private String dsnNotify; 89 private String dsnRet; 90 private Boolean allow8bitmime; 91 private Boolean sendPartial; 92 private String saslRealm; 93 private Boolean quitWait; 94 private Boolean reportSuccess; 95 private String socketFactoryClass; 96 private Boolean socketFactoryFallback; 97 private Integer socketFactoryPort; 98 private String mailExtension; 99 private Boolean startTLSEnable; 100 101 102 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 193 public Integer getPort() { 194 return port; 195 } 196 197 208 public void setPort(Integer port) { 209 this.port = port; 210 } 211 212 215 public Integer getConnectionTimeout() { 216 return connectionTimeout; 217 } 218 219 229 public void setConnectionTimeout(Integer connectionTimeout) { 230 this.connectionTimeout = connectionTimeout; 231 } 232 233 236 public Integer getTimeout() { 237 return timeout; 238 } 239 240 250 public void setTimeout(Integer timeout) { 251 this.timeout = timeout; 252 } 253 254 257 public String getFrom() { 258 return from; 259 } 260 261 273 public void setFrom(String from) { 274 this.from = from; 275 } 276 277 280 public String getLocalhost() { 281 return localhost; 282 } 283 284 296 public void setLocalhost(String localhost) { 297 this.localhost = localhost; 298 } 299 300 303 public String getLocaladdress() { 304 return localaddress; 305 } 306 307 320 public void setLocaladdress(String localaddress) { 321 this.localaddress = localaddress; 322 } 323 324 327 public Integer getLocalport() { 328 return localport; 329 } 330 331 342 public void setLocalport(Integer localport) { 343 this.localport = localport; 344 } 345 346 354 public Boolean getEhlo() { 355 return ehlo; 356 } 357 358 371 public void setEhlo(Boolean ehlo) { 372 this.ehlo = ehlo; 373 } 374 375 381 public Boolean getAuth() { 382 return auth; 383 } 384 385 397 public void setAuth(Boolean auth) { 398 this.auth = auth; 399 } 400 401 412 public Boolean getStartTLSEnable() { 413 return startTLSEnable; 414 } 415 416 434 public void setStartTLSEnable(Boolean startTLSEnable) { 435 this.startTLSEnable = startTLSEnable; 436 } 437 438 445 public String getSubmitter() { 446 return submitter; 447 } 448 449 461 public void setSubmitter(String submitter) { 462 this.submitter = submitter; 463 } 464 465 471 public String getDsnNotify() { 472 return dsnNotify; 473 } 474 475 486 public void setDsnNotify(String dsnNotify) { 487 this.dsnNotify = dsnNotify; 488 } 489 490 495 public String getDsnRet() { 496 return dsnRet; 497 } 498 499 509 public void setDsnRet(String dsnRet) { 510 this.dsnRet = dsnRet; 511 } 512 513 522 public Boolean getAllow8bitmime() { 523 return allow8bitmime; 524 } 525 526 541 public void setAllow8bitmime(Boolean allow8bitmime) { 542 this.allow8bitmime = allow8bitmime; 543 } 544 545 553 public Boolean getSendPartial() { 554 return sendPartial; 555 } 556 557 570 public void setSendPartial(Boolean sendPartial) { 571 this.sendPartial = sendPartial; 572 } 573 574 577 public String getSaslRealm() { 578 return saslRealm; 579 } 580 581 589 public void setSaslRealm(String saslRealm) { 590 this.saslRealm = saslRealm; 591 } 592 593 600 public Boolean getQuitWait() { 601 return quitWait; 602 } 603 604 616 public void setQuitWait(Boolean quitWait) { 617 this.quitWait = quitWait; 618 } 619 620 628 public Boolean getReportSuccess() { 629 return reportSuccess; 630 } 631 632 646 public void setReportSuccess(Boolean reportSuccess) { 647 this.reportSuccess = reportSuccess; 648 } 649 650 657 public String getSocketFactoryClass() { 658 return socketFactoryClass; 659 } 660 661 673 public void setSocketFactoryClass(String socketFactoryClass) { 674 this.socketFactoryClass = socketFactoryClass; 675 } 676 677 685 public Boolean getSocketFactoryFallback() { 686 return socketFactoryFallback; 687 } 688 689 703 public void setSocketFactoryFallback(Boolean socketFactoryFallback) { 704 this.socketFactoryFallback = socketFactoryFallback; 705 } 706 707 713 public Integer getSocketFactoryPort() { 714 return socketFactoryPort; 715 } 716 717 728 public void setSocketFactoryPort(Integer socketFactoryPort) { 729 this.socketFactoryPort = socketFactoryPort; 730 } 731 732 742 public String getMailExtension() { 743 return mailExtension; 744 } 745 746 761 public void setMailExtension(String mailExtension) { 762 this.mailExtension = mailExtension; 763 } 764 765 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 } 874 | Popular Tags |