MTA + MessageQuerry
DNSResolver Projkect added
This commit is contained in:
parent
23836945c9
commit
ddf1c09acb
25
SMTPServer/DNSResolver/DNSResolver.csproj
Normal file
25
SMTPServer/DNSResolver/DNSResolver.csproj
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="**\*.cs" />
|
||||||
|
<EmbeddedResource Include="**\*.resx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NETCore.App">
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.NET.Sdk">
|
||||||
|
<Version>1.0.0-alpha-20161104-2</Version>
|
||||||
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
9
SMTPServer/DNSResolver/Program.cs
Normal file
9
SMTPServer/DNSResolver/Program.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
@ -4,9 +4,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
VisualStudioVersion = 15.0.25914.0
|
VisualStudioVersion = 15.0.25914.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMTPServer", "SMTPServer\SMTPServer.csproj", "{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMTPServer", "SMTPServer\SMTPServer.csproj", "{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{55342A63-351F-4908-B708-DC4111FF34E7} = {55342A63-351F-4908-B708-DC4111FF34E7}
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D43013F8-933F-4ADC-8943-08E91662A070}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D43013F8-933F-4ADC-8943-08E91662A070}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DNSResolver", "DNSResolver\DNSResolver.csproj", "{55342A63-351F-4908-B708-DC4111FF34E7}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -17,6 +22,10 @@ Global
|
|||||||
{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{ABB6A3E6-38B6-4D02-AC9C-91FA69CF03BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{55342A63-351F-4908-B708-DC4111FF34E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{55342A63-351F-4908-B708-DC4111FF34E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{55342A63-351F-4908-B708-DC4111FF34E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{55342A63-351F-4908-B708-DC4111FF34E7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
24
SMTPServer/SMTPServer/Exceptions/NoMailsInQueueException.cs
Normal file
24
SMTPServer/SMTPServer/Exceptions/NoMailsInQueueException.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SMTPServer.Exceptions
|
||||||
|
{
|
||||||
|
class NoMailsInQueueException : Exception
|
||||||
|
{
|
||||||
|
public NoMailsInQueueException() : base()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoMailsInQueueException(string message) : base(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoMailsInQueueException(string message, Exception inner) : base(message, inner)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
SMTPServer/SMTPServer/MTACommands.cs
Normal file
49
SMTPServer/SMTPServer/MTACommands.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SMTPServer
|
||||||
|
{
|
||||||
|
public class MTACommandsDict : Dictionary<MTACommands, String>
|
||||||
|
{
|
||||||
|
public MTACommandsDict()
|
||||||
|
{
|
||||||
|
Add(MTACommands.HELO, "HELO");
|
||||||
|
Add(MTACommands.DATA, "DATA");
|
||||||
|
Add(MTACommands.EXPN, "EXPN");
|
||||||
|
Add(MTACommands.HELP, "HELP");
|
||||||
|
Add(MTACommands.MAIL_FROM, "MAIL FROM");
|
||||||
|
Add(MTACommands.NOOP, "NOOP");
|
||||||
|
Add(MTACommands.QUIT, "QUIT");
|
||||||
|
Add(MTACommands.RCPT_TO, "RCPT TO");
|
||||||
|
Add(MTACommands.RSET, "RSET");
|
||||||
|
Add(MTACommands.SAML_FROM, "SAML FROM");
|
||||||
|
Add(MTACommands.SEND_FROM, "SEND FROM");
|
||||||
|
Add(MTACommands.SOML_FROM, "SOML FROM");
|
||||||
|
Add(MTACommands.TURN, "TURN");
|
||||||
|
Add(MTACommands.VERB, "VERB");
|
||||||
|
Add(MTACommands.VRFY, "VRFY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum MTACommands
|
||||||
|
{
|
||||||
|
HELO,
|
||||||
|
MAIL_FROM,
|
||||||
|
RCPT_TO,
|
||||||
|
DATA,
|
||||||
|
RSET,
|
||||||
|
QUIT,
|
||||||
|
HELP,
|
||||||
|
VRFY,
|
||||||
|
EXPN,
|
||||||
|
VERB,
|
||||||
|
NOOP,
|
||||||
|
TURN,
|
||||||
|
SEND_FROM,
|
||||||
|
SOML_FROM,
|
||||||
|
SAML_FROM
|
||||||
|
}
|
||||||
|
}
|
26
SMTPServer/SMTPServer/Mail.cs
Normal file
26
SMTPServer/SMTPServer/Mail.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SMTPServer
|
||||||
|
{
|
||||||
|
public class Mail
|
||||||
|
{
|
||||||
|
public string _To { get; private set; }
|
||||||
|
public string _From { get; private set; }
|
||||||
|
|
||||||
|
public string _Subject { get; private set; }
|
||||||
|
public string _MessageId { get; private set; }
|
||||||
|
public string _Date { get; private set; }
|
||||||
|
|
||||||
|
public string _MIME_Version { get; private set; }
|
||||||
|
|
||||||
|
public string _Others { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public Mail(string mail)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
SMTPServer/SMTPServer/MailQueue.cs
Normal file
65
SMTPServer/SMTPServer/MailQueue.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using SMTPServer.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SMTPServer
|
||||||
|
{
|
||||||
|
public class MailQueue
|
||||||
|
{
|
||||||
|
private static List<QueueMail> _Mails = null;
|
||||||
|
|
||||||
|
public static void AddToMesssageQueue(Mail mail)
|
||||||
|
{
|
||||||
|
lock (_Mails)
|
||||||
|
{
|
||||||
|
if (_Mails == null)
|
||||||
|
{
|
||||||
|
_Mails = new List<QueueMail>();
|
||||||
|
}
|
||||||
|
_Mails.Add(new QueueMail(mail));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QueueMail GetNextMail()
|
||||||
|
{
|
||||||
|
lock (_Mails)
|
||||||
|
{
|
||||||
|
if(_Mails.Count < 1)
|
||||||
|
{
|
||||||
|
throw new NoMailsInQueueException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var m = _Mails[0];
|
||||||
|
|
||||||
|
_Mails.Remove(m);
|
||||||
|
m._Count++;
|
||||||
|
_Mails.Add(m);
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveMailFromQueue(QueueMail mail)
|
||||||
|
{
|
||||||
|
lock (_Mails)
|
||||||
|
{
|
||||||
|
_Mails.Remove(mail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class QueueMail
|
||||||
|
{
|
||||||
|
public DateTime _QueueEntered { get; private set; }
|
||||||
|
public int _Count { get; set; }
|
||||||
|
public Mail _Mail { get; private set; }
|
||||||
|
|
||||||
|
public QueueMail (Mail mail)
|
||||||
|
{
|
||||||
|
_Mail = mail;
|
||||||
|
_QueueEntered = DateTime.Now;
|
||||||
|
_Count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
SMTPServer/SMTPServer/MailTransferAgent.cs
Normal file
56
SMTPServer/SMTPServer/MailTransferAgent.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using SMTPServer.Exceptions;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace SMTPServer
|
||||||
|
{
|
||||||
|
class MailTransferAgent
|
||||||
|
{
|
||||||
|
static MTACommandsDict _MTACommandsDict = new MTACommandsDict();
|
||||||
|
static Thread _Thread;
|
||||||
|
|
||||||
|
public static void StartMailTransferAgent()
|
||||||
|
{
|
||||||
|
_Thread = new Thread(new ThreadStart(MTA));
|
||||||
|
_Thread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MTA()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var mail = MailQueue.GetNextMail();
|
||||||
|
} catch (NoMailsInQueueException) {
|
||||||
|
Thread.Sleep(100);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var charset = Encoding.UTF8;
|
||||||
|
|
||||||
|
var dnsname = GetDNSName("");
|
||||||
|
var client = new StartTcpConnection(25, new IPAddress(GetIpFromDNS(dnsname)), charset);
|
||||||
|
|
||||||
|
if (!client.Connected) ; //ToDo Errorfall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetDNSName(string mailTo)
|
||||||
|
{
|
||||||
|
var parts = mailTo.Split('@');
|
||||||
|
var domain = parts[1];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] GetIpFromDNS(string dnsname)
|
||||||
|
{
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -53,6 +53,7 @@ namespace SMTPServer
|
|||||||
listener.Start();
|
listener.Start();
|
||||||
_Listener = listener;
|
_Listener = listener;
|
||||||
Thread thread = new Thread(new ThreadStart(ListenerAsync));
|
Thread thread = new Thread(new ThreadStart(ListenerAsync));
|
||||||
|
thread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ListenerAsync()
|
private async void ListenerAsync()
|
||||||
|
@ -1,16 +1,68 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace SMTPServer
|
namespace SMTPServer
|
||||||
{
|
{
|
||||||
class StartTcpConnection
|
class StartTcpConnection : Socket
|
||||||
{
|
|
||||||
public StartTcpConnection(int port, IPAddress destination)
|
|
||||||
{
|
{
|
||||||
|
private List<string> _Lines = new List<string>();
|
||||||
|
private string _Others { get; set; }
|
||||||
|
private Encoding _Encoding { get; set; }
|
||||||
|
|
||||||
|
public StartTcpConnection(int port, IPAddress destination, Encoding encoding) : base (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
|
||||||
|
{
|
||||||
|
this.Connect(new IPEndPoint(destination, port));
|
||||||
|
Thread readLines = new Thread(new ThreadStart(ReadClientInput));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ReadClientInput()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[this.ReceiveBufferSize];
|
||||||
|
Receive(buffer);
|
||||||
|
|
||||||
|
var str = _Encoding.GetString(buffer);
|
||||||
|
lock (_Others)
|
||||||
|
{
|
||||||
|
_Others += str;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckLines();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckLines()
|
||||||
|
{
|
||||||
|
lock (_Others)
|
||||||
|
{
|
||||||
|
var line = "";
|
||||||
|
foreach (char c in _Others)
|
||||||
|
{
|
||||||
|
if (c.Equals('\n'))
|
||||||
|
{
|
||||||
|
lock (_Lines)
|
||||||
|
{
|
||||||
|
_Lines.Add(line);
|
||||||
|
line = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else line += c;
|
||||||
|
}
|
||||||
|
_Others = line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetLine()
|
||||||
|
{
|
||||||
|
lock (_Lines)
|
||||||
|
{
|
||||||
|
return _Lines[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user