public static void StartServer(string[] args) { Logger.SetLevel(Logger.InitLevel.Debug); if (args.Length < 1) { Console.WriteLine("Command error, expected at least domain name for server to use."); Console.WriteLine("Usage: start <domainName> <?portNum?> <?allowExtsBool?>"); return; } if (localServer != null) { Console.WriteLine("Process local SMTP server is already running!"); return; } if (args.Length == 1) { localServer = new SMTPServer(args[0]); } else if (args.Length == 2) { localServer = new SMTPServer(args[0], int.Parse(args[1])); } else if (args.Length == 3) { localServer = new SMTPServer(args[0], int.Parse(args[1]), bool.Parse(args[2])); } CLInterface.inst.AddPumpCallback("SMTP", localServer.MessagePump); }
public RemoteConnection(TcpClient client, Dictionary <string, string> config, SMTPServer owner, int connectionId) { tcpClient = client; serverConfig = config; ownerServer = owner; connId = connectionId; //setting up defaults in config if (!config.ContainsKey("Domain")) { config.Add("Domain", "NoDomain"); } if (!config.ContainsKey("MessageMaxBytes")) { config.Add("MessageMaxBytes", "1000000"); } recvBuff = new byte[config.ContainsKey("BufferSize") ? int.Parse(config["BufferSize"]) : 4096]; try { tcpClient.ReceiveBufferSize = recvBuff.Length; tcpClient.SendBufferSize = recvBuff.Length; tcpStream = tcpClient.GetStream(); tcpStream.BeginRead(recvBuff, 0, recvBuff.Length, ProcessRecvData, null); SendResponse(new SMTPResult(SMTPResponseCode.ServerReady, config["Domain"] + " SEMPTY Server is ready for, welcome.")); } catch (Exception e) { Logger.Critical?.WriteLine("TCP critical error, cannot establish connection: " + e.ToString()); shutdownQueued = true; ownerServer.QueueEndConnection(connId); } }
public static void StopServer(string[] args) { if (localServer == null) { Console.WriteLine("No SMTP server running."); return; } CLInterface.inst.RemovePumpCallback("SMTP"); localServer.Shutdown(); localServer = null; }