001 package com.hs.mail.smtp.server;
002
003 import java.io.FileNotFoundException;
004 import java.io.FileOutputStream;
005 import java.io.PrintStream;
006
007 import org.springframework.beans.factory.InitializingBean;
008
009 import com.hs.mail.container.config.Config;
010 import com.hs.mail.container.server.DefaultServer;
011 import com.hs.mail.container.server.socket.DefaultServerSocketFactory;
012 import com.hs.mail.container.server.socket.TLSServerSocketFactory;
013
014 /**
015 *
016 * @author Won Chul Doh
017 * @since Jun 20, 2010
018 *
019 */
020 public class SmtpServer extends DefaultServer implements InitializingBean {
021
022 private boolean useTLS = false;
023
024 public void setUseTLS(boolean useTLS) {
025 this.useTLS = useTLS;
026 }
027
028 public boolean isUseTLS() {
029 return useTLS;
030 }
031
032 public void afterPropertiesSet() throws Exception {
033 // Configure the server
034 connectionTimeout = (int) Config.getNumberProperty("smtp_timeout", 300000);
035 connectionHandler = new SmtpConnectionHandler();
036
037 if ("true".equals(Config.getProperty("smtp_trace_protocol", "false"))) {
038 ((SmtpConnectionHandler) connectionHandler).setDebug(true);
039 String path = Config.getProperty("smtp_protocol_log", null);
040 if (path != null) {
041 try {
042 FileOutputStream fos = new FileOutputStream(path);
043 ((SmtpConnectionHandler) connectionHandler)
044 .setDebugOut(new PrintStream(fos));
045 } catch (FileNotFoundException e) {
046 // Ignore this exception
047 }
048 }
049 }
050 serverSocketFactory = (isUseTLS())
051 ? new TLSServerSocketFactory(Config.getSSLContext())
052 : new DefaultServerSocketFactory();
053
054 super.configure();
055
056 // Start the server
057 start();
058 }
059
060 }