public SmtpResponse Data(byte[] data) { SmtpResponse response = new SmtpResponse(); var encodingresult = Lib.Helper.EncodingDetector.GetEmailEncoding(data); string text = GetString(data, encodingresult); text = text.Replace("\r\n..", "\r\n."); if (!string.IsNullOrWhiteSpace(text)) { this.MessageBody = text; this._buffer = null; response.Code = 250; response.Message = "Message queued"; response.SessionCompleted = true; } else { response.Code = 550; response.Message = "Message body not found"; } this.Log.Add(new SmtpCommand() { CommandLine = ".", Name = SmtpCommandName.ENDDOT }, response); this.State = CommandState.Helo; return(response); }
internal SmtpResponse AuthCommand(string CommandLine) { var response = new SmtpResponse(); if (this.State == CommandState.Auth) { this.State = CommandState.AuthUser; this.UserName = Encoding.ASCII.GetString(Convert.FromBase64String(CommandLine)); response.Code = 334; response.Message = Convert.ToBase64String(Encoding.ASCII.GetBytes("Password:"******"@") > -1 && Utility.AddressUtility.IsValidEmailAddress(this.UserName)) { var emailaddressObj = Utility.AddressUtility.GetEmailAddress(this.UserName); if (emailaddressObj != null) { username = Kooboo.Data.GlobalDb.Users.GetUserName(emailaddressObj.UserId); this.OrganizationId = emailaddressObj.OrgId; } } var user = Kooboo.Data.GlobalDb.Users.Validate(username, this.Password); IsAuthenticated = user != null; if (this.OrganizationId == default(Guid) && user != null) { this.OrganizationId = user.CurrentOrgId; } } if (IsAuthenticated) { response.Code = 235; response.Message = "Authentication completed"; Kooboo.Data.Service.UserLoginProtection.AddLoginOK(username, this.ClientIP); } else { response.Code = 535; response.Message = "Authentication failed"; Kooboo.Data.Service.UserLoginProtection.AddLoginFail(username, this.ClientIP); } } return(response); }
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 DataCommand(string CommandLine) { if (CommandLine == ".") { SmtpResponse response = new SmtpResponse(); string msgbody = null; if (_buffer != null) { msgbody = _buffer.ToString().Replace("\r\n..", "\r\n."); } if (!string.IsNullOrEmpty(msgbody)) { this.MessageBody = msgbody; this._buffer = null; response.Code = 250; response.Message = "Message queued"; response.SessionCompleted = true; } else { response.Code = 550; response.Message = "Message body not found"; } this.Log.Add(new SmtpCommand() { CommandLine = CommandLine, Name = SmtpCommandName.ENDDOT }, response); this.State = CommandState.Helo; return(response); } else { if (CommandLine == "\r\n") { this.buffer.AppendLine(); } else { this.buffer.AppendLine(CommandLine); } return(new SmtpResponse() { SendResponse = false }); } }
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); }