diff --git a/.gitignore b/.gitignore index 3478d93..5d2c933 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea /uploads/* +*/logs/* /depreciated/* # General Apple files diff --git a/SMTP/Program.cs b/SMTP/Program.cs new file mode 100644 index 0000000..f32c838 --- /dev/null +++ b/SMTP/Program.cs @@ -0,0 +1,87 @@ +// See https://aka.ms/new-console-template for more information + +using Serilog; +using Serilog.Core; +using Serilog.Events; +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; + +namespace SMTPServer +{ + public class MyGlobalVariables + { + public static bool KeepRunning { get; set; } + public AutoResetEvent connectionWaitHandle = new AutoResetEvent(false); + } + + class Program + { + static void Main() + { + // Create the Serilog object + Log.Logger = new LoggerConfiguration() + .Enrich.With(new ThreadIdEnricher()) + .Enrich.WithProperty("Version", "0.0.1") + //.ReadFrom.AppSettings() + .MinimumLevel.Verbose() + .WriteTo.Console( + outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}, TID:{ThreadId}] {Message:lj}{NewLine}{Exception}") + .WriteTo.File("log.txt", + rollingInterval: RollingInterval.Day, + rollOnFileSizeLimit: true, + outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}, TID:{ThreadId}] {Message:lj}{NewLine}{Exception}") + .CreateLogger(); + Log.Verbose("Starting application"); + + // Create the TCP listening object + int port = 2525; + System.Net.IPAddress ListenIPAddress = System.Net.IPAddress.Any; + var MyTCPlistener = new TcpListener(ListenIPAddress, port); + MyTCPlistener.Start(); + + MyGlobalVariables.KeepRunning = true; + + while (MyGlobalVariables.KeepRunning) + { + IAsyncResult result = MyTCPlistener.BeginAcceptTcpClient(SmtpThreadWork.AcceptConnection, MyTCPlistener); + MyGlobalVariables.connectionWaitHandle.WaitOne(); // Wait until a client has begun handling an event + MyGlobalVariables.connectionWaitHandle.Reset(); // Reset wait handle or the loop goes as fast as it can (after first request) + } + + Log.CloseAndFlush(); + } + class ThreadIdEnricher : ILogEventEnricher + { + public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) + { + logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty( + "ThreadId", Thread.CurrentThread.ManagedThreadId)); + } + } + } + public class SmtpThreadWork + { + public static void AcceptConnection(IAsyncResult NewConnection) + { + Log.Debug("Starting a new thread"); + TcpListener listener = (TcpListener)NewConnection.AsyncState; + TcpClient client = listener.EndAcceptTcpClient(NewConnection); + + + } + } + public class ThreadWork + { + public static void DoWork() + { + for (int i = 0; i < 3; i++) + { + Log.Information("Working thread..." + i); + Thread.Sleep(100); + } + } + } +} \ No newline at end of file diff --git a/SMTP/SMTP.csproj b/SMTP/SMTP.csproj new file mode 100644 index 0000000..ce50b7f --- /dev/null +++ b/SMTP/SMTP.csproj @@ -0,0 +1,28 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + + + + diff --git a/SMTP/program.config b/SMTP/program.config new file mode 100644 index 0000000..6ba4ea9 --- /dev/null +++ b/SMTP/program.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dotMailServer.sln b/dotMailServer.sln new file mode 100644 index 0000000..d4d506d --- /dev/null +++ b/dotMailServer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMTP", "SMTP\SMTP.csproj", "{A91B3684-0F04-4A7A-AB29-6B287466B47A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A91B3684-0F04-4A7A-AB29-6B287466B47A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A91B3684-0F04-4A7A-AB29-6B287466B47A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A91B3684-0F04-4A7A-AB29-6B287466B47A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A91B3684-0F04-4A7A-AB29-6B287466B47A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6EF1E636-0628-47B2-81A6-6488ED09654C} + EndGlobalSection +EndGlobal