diff --git a/MailServer/MailServer/Configuration.cs b/MailServer/MailServer/Configuration.cs index d3db0d5..fb90f2d 100644 --- a/MailServer/MailServer/Configuration.cs +++ b/MailServer/MailServer/Configuration.cs @@ -7,6 +7,7 @@ namespace MailServer public class Configuration { public const string Hostname = "localhost"; - public bool STARTTLS_Active = false; + public const bool STARTTLS_Active = true; + public const int MaxMessageSizeInKb = 500000; } } diff --git a/MailServer/MailServer/SMTPServer/MTACommands.cs b/MailServer/MailServer/SMTPServer/MTACommands.cs index 537ace2..9117df3 100644 --- a/MailServer/MailServer/SMTPServer/MTACommands.cs +++ b/MailServer/MailServer/SMTPServer/MTACommands.cs @@ -69,6 +69,13 @@ namespace MailServer.SMTPServer AUTH_LOGIN } + public enum Extensions + { + PIPELINING, + SIZE, + STARTTLS, + } + public enum ResponseCodes { C211 = 211, diff --git a/MailServer/MailServer/SMTPServer/SmtpServerSession.cs b/MailServer/MailServer/SMTPServer/SmtpServerSession.cs index 62805ba..b05004e 100644 --- a/MailServer/MailServer/SMTPServer/SmtpServerSession.cs +++ b/MailServer/MailServer/SMTPServer/SmtpServerSession.cs @@ -79,7 +79,7 @@ namespace MailServer.SMTPServer var res3 = context.Accounts.Where(x => x.Domain.Equals(domain) && x.CatchAll == true); if (res3.Count() < 1) { - //ToDo unmöglich machen!! + accountId = 0; } else { @@ -145,6 +145,22 @@ namespace MailServer.SMTPServer switch (command.Command.ToUpper()) { case "EHLO": + if (command.Parameters.Length < 1) + { + SendResponse(ResponseCodes.C501, "Hostname Required"); + return; + } + SenderHostname = command.Parameters[0]; + Initialized = true; + SendExtensionResponse(Extensions.PIPELINING); + + if (Configuration.STARTTLS_Active) + { + SendExtensionResponse(Extensions.STARTTLS); + } + + SendResponse(ResponseCodes.C250, "SIZE " + (Configuration.MaxMessageSizeInKb * 1000).ToString()); + return; case "HELO": if (command.Parameters.Length < 1) { diff --git a/MailServer/MailServer/SMTPServer/SmtpSession.cs b/MailServer/MailServer/SMTPServer/SmtpSession.cs index fd4b01a..bf7fcdf 100644 --- a/MailServer/MailServer/SMTPServer/SmtpSession.cs +++ b/MailServer/MailServer/SMTPServer/SmtpSession.cs @@ -36,14 +36,18 @@ namespace MailServer.SMTPServer Worker.Start(); } + public void SendExtensionResponse(Extensions extension) => SendResponse("250-" + extension.ToString()); + public void SendResponse(ResponseCodes responseCode) => SendResponse(responseCode, ""); - public void SendResponse(ResponseCodes responseCode, string args) + public void SendResponse(ResponseCodes responseCode, string args) => SendResponse(((int)responseCode).ToString() + " " + args); + + + public void SendResponse(string response) { - var text = ((int)responseCode).ToString(); - Logging.AddLogMessage(Logging.LoggingType.DEBUG, "Send back: " + text + " " + args); - text += " " + args +'\r' + '\n'; - var bytes = Encoding.UTF8.GetBytes(text); + Logging.AddLogMessage(Logging.LoggingType.INFO, response); + response += '\r' + '\n'; + var bytes = Encoding.UTF8.GetBytes(response); Stream.Write(bytes, 0, bytes.Length); }