Example #1
0
        private static Pop3Client TestGetPop3Client(string pop3_server, string pop3_account, string pop3_password, int pop3_port, bool use_ssl)
        {
            var pop = MailClientBuilder.Pop();

            Debug.WriteLine("Connect to Pop3:");

            var watch = new Stopwatch();

            watch.Start();

            var result = use_ssl ?
                         pop.ConnectSsl(pop3_server, pop3_port, pop3_account, pop3_password) :
                         pop.Connect(pop3_server, pop3_port, pop3_account, pop3_password);

            watch.Stop();

            Debug.WriteLine("Elapsed Connect pop: " + watch.ElapsedMilliseconds);

            if (!result.StartsWith("+"))
            {
                throw new Exception("Bad connection result: " + result);
            }

            return(pop);
        }
Example #2
0
        public static List <string> TestGetPopHeaderMD5(string pop3_server, string pop3_account, string pop3_password, int pop3_port, bool use_ssl)
        {
            var headers_md5 = new List <string>();

            var pop = MailClientBuilder.Pop();

            Debug.WriteLine("Pop3:");
            try
            {
                pop = TestGetPop3Client(pop3_server, pop3_account, pop3_password, pop3_port, use_ssl);

                var watch = new Stopwatch();

                watch.Start();

                for (var i = 1; i <= pop.MessageCount; i++)
                {
                    try
                    {
                        var header            = pop.RetrieveHeaderObject(i);
                        var unique_identifier = string.Format("{0}|{1}|{2}|{3}", header.From.Email, header.Subject, header.DateString, header.MessageId);
                        var md5 = unique_identifier.GetMD5();
                        headers_md5.Add(md5);
                        Debug.WriteLine("# " + i + "MD5: " + md5);
                        Debug.WriteLine("unique_identifier: " + unique_identifier);
                    }
                    catch
                    { //SKEEP RetrieveHeader ERROR
                        if (!pop.IsConnected)
                        {
                            break;
                        }
                    }
                }

                watch.Stop();

                Debug.WriteLine("Elapsed Get pop md5: " + watch.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (pop != null && pop.IsConnected)
                {
                    pop.Disconnect();
                }
            }

            return(headers_md5);
        }
Example #3
0
 public static bool TryTestPop(MailServerSettings settings, out string last_error)
 {
     try
     {
         last_error = String.Empty;
         return(Test(MailClientBuilder.Pop(), settings));
     }
     catch (Exception ex)
     {
         last_error = ex.Message;
         return(false);
     }
 }
Example #4
0
        public bool Test()
        {
            BaseProtocolClient ingoing_client = (Account.Imap) ? (BaseProtocolClient)MailClientBuilder.Imap() : MailClientBuilder.Pop();

            MailServerHelper.Test(ingoing_client, new MailServerSettings
            {
                Url                = Account.Server,
                Port               = Account.Port,
                AccountName        = Account.Account,
                AccountPass        = Account.Password,
                AuthenticationType = Account.AuthenticationTypeIn,
                EncryptionType     = Account.IncomingEncryptionType
            });

            MailServerHelper.TestSmtp(new MailServerSettings
            {
                Url                = Account.SmtpServer,
                Port               = Account.SmtpPort,
                AccountName        = Account.SmtpAccount,
                AccountPass        = Account.SmtpPassword,
                AuthenticationType = Account.AuthenticationTypeSmtp,
                EncryptionType     = Account.OutcomingEncryptionType
            });

            return(true);
        }
Example #5
0
        private bool RetrievePop(int max_messages_per_session, WaitHandle stop_event, out int processed_messages_count)
        {
            var pop = MailClientBuilder.Pop();

            try
            {
                pop.Authenticated += OnAuthenticated;

                _log.Debug("Connecting to {0}", Account.EMail);

                switch (Account.IncomingEncryptionType)
                {
                case EncryptionType.StartTLS:
                    pop.ConnectTLS(Account.Server, Account.Port);
                    break;

                case EncryptionType.SSL:
                    pop.ConnectSsl(Account.Server, Account.Port);
                    break;

                case EncryptionType.None:
                    pop.Connect(Account.Server, Account.Port);
                    break;
                }

                if (Account.AuthenticationTypeIn == SaslMechanism.Login)
                {
                    pop.Login(Account.Account, Account.Password, Account.Server);
                }
                else
                {
                    pop.Authenticate(Account.Account, Account.Password, Account.AuthenticationTypeIn);
                }
                UpdateTimeCheckedIfNeeded();

                _log.Debug("UpdateStats()");

                pop.UpdateStats();

                _log.Debug("GetCAPA()");

                GetCAPA(pop);

                _log.Info("Account: MessagesCount={0}, TotalSize={1}, UIDL={2}, LoginDelay={3}",
                          pop.MessageCount, pop.TotalSize, IsUidlSupported, Account.ServerLoginDelay);

                if (ProcessMessagesPop(pop, max_messages_per_session, stop_event, out processed_messages_count))
                { // If all messages are proccessed
                    Account.MessagesCount = pop.MessageCount;
                    Account.Size          = pop.TotalSize;
                    _log.Info("Account '{0}' has been processed.", Account.EMail);
                }

                LastRetrieve = DateTime.UtcNow;

                return(true);
            }
            catch (Pop3Exception e)
            {
                if (e.Command.StartsWith("USER") || e.Command.StartsWith("PASS"))
                {
                    if (OnAuthFailed != null)
                    {
                        OnAuthFailed(Account, e.Response);
                    }

                    _log.Warn("Retrieve() Pop3: {0} Port: {1} Account: '{2}' ErrorMessage:\r\n{3}\r\n",
                              Account.Server, Account.Port, Account.Account, e.Message);
                }
                else
                {
                    _log.Error("Retrieve() Pop3: {0} Port: {1} Account: '{2}' ErrorMessage:\r\n{3}\r\n",
                               Account.Server, Account.Port, Account.Account, e.ToString());
                }

                throw;
            }
            finally
            {
                try
                {
                    if (pop.IsConnected)
                    {
                        pop.Disconnect();
                    }
                }
                catch { }
            }
        }
Example #6
0
        public void DownloadMessage(string uidl, string destination_path)
        {
            var pop = MailClientBuilder.Pop();

            try
            {
                _log.Debug("Connecting to {0}", Account.EMail);

                switch (Account.IncomingEncryptionType)
                {
                case EncryptionType.StartTLS:
                    pop.ConnectTLS(Account.Server, Account.Port);
                    break;

                case EncryptionType.SSL:
                    pop.ConnectSsl(Account.Server, Account.Port);
                    break;

                case EncryptionType.None:
                    pop.Connect(Account.Server, Account.Port);
                    break;
                }

                if (Account.AuthenticationTypeIn == SaslMechanism.Login)
                {
                    pop.Login(Account.Account, Account.Password, Account.Server);
                }
                else
                {
                    pop.Authenticate(Account.Account, Account.Password, Account.AuthenticationTypeIn);
                }


                _log.Debug("GetCAPA()");

                GetCAPA(pop);

                _log.Info("Account: MessagesCount={0}, TotalSize={1}, UIDL={2}, LoginDelay={3}",
                          pop.MessageCount, pop.TotalSize, IsUidlSupported, Account.ServerLoginDelay);

                if (pop.UniqueIdExists(uidl))
                {
                    _log.Info("Message with this uidl exists!");

                    var index = pop.GetMessageIndex(uidl);

                    _log.Info("StoreMessage(index: {0})", index);

                    pop.StoreMessage(index, false, destination_path);

                    if (File.Exists(destination_path))
                    {
                        _log.Info("Message stored successfully!\r\n");
                    }
                    else
                    {
                        _log.Error("Message is missing in destination path!\r\n");
                    }
                }
                else
                {
                    _log.Info("Message with this uidl not exists!\r\n");
                }
            }
            catch (Pop3Exception e)
            {
                if (e.Command.StartsWith("USER") || e.Command.StartsWith("PASS"))
                {
                    if (OnAuthFailed != null)
                    {
                        OnAuthFailed(Account, e.Response);
                    }

                    _log.Warn("Retrieve() Pop3: {0} Port: {1} Account: '{2}' ErrorMessage:\r\n{3}\r\n",
                              Account.Server, Account.Port, Account.Account, e.Message);
                }
                else
                {
                    _log.Error("Retrieve() Pop3: {0} Port: {1} Account: '{2}' ErrorMessage:\r\n{3}\r\n",
                               Account.Server, Account.Port, Account.Account, e.ToString());
                }

                throw;
            }
            finally
            {
                try
                {
                    if (pop.IsConnected)
                    {
                        pop.Disconnect();
                    }
                }
                catch { }
            }
        }
Example #7
0
        public static void TestPOPReceiveMessage(string pop3_server, string pop3_account, string pop3_password, int pop3_port, bool use_ssl, string uidl)
        {
            var pop = MailClientBuilder.Pop();

            try
            {
                _log.Debug("Connecting to {0}", pop3_account);

                var result = use_ssl ? pop.ConnectSsl(pop3_server, pop3_port, pop3_account, pop3_password) :
                             pop.Connect(pop3_server, pop3_port, pop3_account, pop3_password);

                if (!result.StartsWith("+"))
                {
                    return;
                }
                if (pop.UniqueIdExists(uidl))
                {
                    _log.Info("Message with this uidl exists!");

                    var index = pop.GetMessageIndex(uidl);

                    _log.Info("StoreMessage(index: {0})", index);

                    var destination_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"strange.eml");

                    pop.UpdateStats();

                    //pop.StoreMessage(index, false, destination_path);

                    var message = pop.RetrieveMessageObject(index);

                    var mail_info = new MailMessageItem(message);

                    _log.Info(mail_info.HtmlBody);

                    if (File.Exists(destination_path))
                    {
                        _log.Info("Message stored successfully!\r\n");
                    }
                    else
                    {
                        _log.Error("Message is missing in destination path!\r\n");
                    }
                }
                else
                {
                    _log.Info("Message with this uidl not exists!\r\n");
                }
            }
            catch (Pop3Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                try
                {
                    if (pop.IsConnected)
                    {
                        pop.Disconnect();
                    }
                }
                catch
                { }
            }
        }