internal SmtpResponse HeloCommand(string CommandLine) { var response = new SmtpResponse(); var command = SmtpCommand.Parse(CommandLine); // TODO validate the incoming domain... if (command.Name == SmtpCommandName.HELO) { if (!string.IsNullOrEmpty(command.Value)) { response.Code = 250; response.Message = "Hello " + command.Value + " Kooboo Smtp Server"; this.State = CommandState.Body; this.ClientHostName = command.Value; } else { response.Code = 501; response.Message = "Hostname required"; } } else if (command.Name == SmtpCommandName.EHLO) { if (!string.IsNullOrEmpty(command.Value)) { response.Code = 250; response.Seperator = '-'; response.Message = "Hello " + command.Value + "\r\n250-SIZE 20480000\r\n250-AUTH LOGIN\r\n250 OK"; this.State = CommandState.Body; this.ClientHostName = command.Value; } else { response.Code = 501; response.Message = "Hostname required"; } } else if (command.Name == SmtpCommandName.UNKNOWN) { response.Code = 550; response.Message = "bad command"; } else if (command.Name == SmtpCommandName.QUIT) { response.Code = 221; response.Message = "Goodbye"; response.Close = true; } else { response.Code = 502; response.Message = "HELO or EHLO first"; } this.Log.Add(command, response); return(response); }
internal SmtpResponse BodyCommand(string CommandLine) { var response = new SmtpResponse(); var command = SmtpCommand.Parse(CommandLine); if (command.Name == SmtpCommandName.AUTHLOGIN) { if (string.IsNullOrEmpty(command.Value)) { this.State = CommandState.Auth; response.Code = 334; response.Message = Convert.ToBase64String(Encoding.ASCII.GetBytes("Username:"******"Password:"******"Sender address must be specified"; } else if (!ValidMailFrom(command.Value)) { response.Code = 550; response.Message = "Invalid Sender address"; } else { response.Code = 250; response.Message = "Sender OK"; } } else if (command.Name == SmtpCommandName.RCPTTO) { if (string.IsNullOrEmpty(command.Value)) { response.Code = 550; response.Message = "Recipient address must be specified"; } else { var validateResult = ValidateRecipient(command.Value); if (validateResult.IsOkToSend) { response.Code = 250; response.Message = "Recipient OK"; } else { response.Code = 550; response.Message = validateResult.ErrorMessage; } } } else if (command.Name == SmtpCommandName.DATA) { //public static string DataStart = "354 "; this.State = CommandState.Data; response.Code = 354; response.Message = "End data with <CLRF>.<CLRF>"; } else if (command.Name == SmtpCommandName.QUIT) { response.Code = 221; response.Message = "Goodbye"; response.Close = true; } else { response.Code = 550; response.Message = "Invalid command"; } this.Log.Add(command, response); return(response); }