Beispiel #1
0
        private async Task Loop()
        {
            _cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = _cancellationTokenSource.Token;

            while (!cancellationToken.IsCancellationRequested)
            {
                var needawait = false;
                try
                {
                    var cid = _nextConnectionId++;
                    _logger.LogInformation($"<ac {cid} {Thread.CurrentThread.ManagedThreadId}");
                    var tcpClient = await _listener.AcceptTcpClientAsync();

                    _logger.LogInformation($">ac {cid} {Thread.CurrentThread.ManagedThreadId} {tcpClient.Client.RemoteEndPoint}");

                    var session = new SmtpConnector(this, tcpClient, cid);
                    _ = session.Accept();
                }
                catch (Exception ex)
                {
                    Kooboo.Data.Log.Instance.Exception.Write(DateTime.Now.ToString() + ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source);
                    needawait = true;
                }
                if (needawait)
                {
                    await Task.Delay(200);
                }
            }
        }
Beispiel #2
0
        public async void Start()
        {
            if (Lib.Helper.NetworkHelper.IsPortInUse(Port))
            {
                return;
            }

            _listener = new TcpListener(new IPEndPoint(IPAddress.Any, Port));
            _listener.Start();

            _cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = _cancellationTokenSource.Token;

            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    var cid = _nextConnectionId++;
                    _logger.LogInformation($"<ac {cid} {Thread.CurrentThread.ManagedThreadId}");
                    var tcpClient = await _listener.AcceptTcpClientAsync();

                    _logger.LogInformation($">ac {cid} {Thread.CurrentThread.ManagedThreadId} {tcpClient.Client.RemoteEndPoint}");

                    var session = new ImapSession(this, tcpClient);
                    _ = session.Start();
                }
                catch
                {
                }
            }
        }
Beispiel #3
0
        public static Task Receive(string MailFrom, List <string> Rcptos, string MessageBody)
        {
            _logger.LogInformation($"{MailFrom},{String.Join("|", Rcptos)},Received");

            var msginfo = Kooboo.Mail.Utility.MessageUtility.ParseMeta(MessageBody);

            return(Receive(MailFrom, Rcptos, MessageBody, msginfo));
        }
Beispiel #4
0
        public static async Task <ActionResponse> Send(string MailFrom, string RcptTo, string MessageContent)
        {
            try
            {
                var result = await DoSend(MailFrom, RcptTo, MessageContent);

                if (result.Success)
                {
                    _logger.LogInformation($"{MailFrom},{RcptTo},Delivered,");
                }
                else
                {
                    _logger.LogInformation($"{MailFrom},{RcptTo},Bounced,{result.Message}");
                }
                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"{MailFrom},{RcptTo},Exception,{ex.Message}");
                throw;
            }
        }