39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace MailServer.SMTPServer
|
|
{
|
|
public class SmtpPortListener
|
|
{
|
|
private static List<int> Ports { get; set; }
|
|
private int Port { get; set; }
|
|
private TcpListener Listener;
|
|
|
|
public SmtpPortListener(int port)
|
|
{
|
|
Port = port;
|
|
Logging.AddLogMessage(Logging.LoggingType.INFO, "Start TCP listener on port: " + Port);
|
|
Thread thread = new Thread(StartListeningAsync);
|
|
thread.Start();
|
|
}
|
|
|
|
public async void StartListeningAsync()
|
|
{
|
|
Listener = new TcpListener(IPAddress.Any, Port);
|
|
Listener.Start();
|
|
|
|
while (true)
|
|
{
|
|
var client = await Listener.AcceptTcpClientAsync();
|
|
var ip = (IPEndPoint)client.Client.RemoteEndPoint;
|
|
Logging.AddLogMessage(Logging.LoggingType.INFO, "New Client Logged in with ip: " + ip.Address.ToString() + "On port: " + Port + " to port: " + ip.Port);
|
|
new SmtpServerSession(client);
|
|
}
|
|
}
|
|
}
|
|
}
|