Beispiel #1
0
    private void ReadMail()
    {
        var client = new Pop3Client();

        client.Connect("mail.epicsportexchange.com", "*****@*****.**", "vRa77330");
        var messages = client.List().Where(x => !x.Retrieved).ToList();

        if (!messages.Any())
        {
            client.Disconnect();
            return;
        }
        using (var context = new Entities())
        {
            foreach (var message in messages)
            {
                client.Retrieve(message);
                switch (message.Subject)
                {
                case "Mirror":
                    AddMessage(message, context);
                    break;

                case "Groceries":
                    AddGrocery(message, context);
                    break;
                }

                client.Delete(message);
            }
            context.SaveChanges();
        }
        client.Disconnect();
    }
        public void DeleteFailNullArgument()
        {
            Mock <INetworkOperations> mockNetworkOperations = new Mock <INetworkOperations>();

            mockNetworkOperations.Setup(no => no.Read()).Returns("+OK");

            Pop3Client pop3Client = new Pop3Client(mockNetworkOperations.Object);

            Assert.IsFalse(pop3Client.IsConnected);

            pop3Client.Connect("SERVER", "USERNAME", "PASSWORD", true);
            Assert.IsTrue(pop3Client.IsConnected);

            pop3Client.Delete(null);
        }
        public void DeleteFailNotConnect()
        {
            Mock <INetworkOperations> mockNetworkOperations = new Mock <INetworkOperations>();

            mockNetworkOperations.Setup(no => no.Read()).Returns("+OK");

            Pop3Client pop3Client = new Pop3Client(mockNetworkOperations.Object);

            Assert.IsFalse(pop3Client.IsConnected);

            pop3Client.Delete(new Pop3Message()
            {
                Number = 1
            });
        }
        public void DeleteOk()
        {
            Mock <INetworkOperations> mockNetworkOperations = new Mock <INetworkOperations>();

            mockNetworkOperations.Setup(no => no.Read()).Returns("+OK");

            Pop3Client pop3Client = new Pop3Client(mockNetworkOperations.Object);

            Assert.IsFalse(pop3Client.IsConnected);

            pop3Client.Connect("SERVER", "USERNAME", "PASSWORD", false);

            pop3Client.Delete(new Pop3Message()
            {
                Number = 1
            });
        }
        private IList <SidePOPMailMessage> check_email()
        {
            IList <SidePOPMailMessage> messages = new List <SidePOPMailMessage>();

            try
            {
                pop3_client.Connect();
                pop3_client.Authenticate();
                pop3_client.GetStatistics();

                foreach (Pop3ListItemResult item in pop3_client.List())
                {
                    SidePOPMailMessage message = pop3_client.RetrieveExtendedMailMessage(item);
                    messages.Add(message);

                    pop3_client.Delete(item);
                }
                if (pop3_client.Client.Connected)
                {
                    pop3_client.SendNoOperation();
                }
            }
            catch (Exception ex)
            {
                Log.bound_to(this).log_an_error_event_containing("{0} had an error:{1}{2}", ApplicationParameters.name, Environment.NewLine, ex.ToString());
            }
            finally
            {
                try
                {
                    pop3_client.Quit();
                    pop3_client.Disconnect();
                }
                catch (Exception ex)
                {
                    Log.bound_to(this).log_an_error_event_containing("{0} had an error:{1}{2}", ApplicationParameters.name, Environment.NewLine, ex.ToString());
                }
            }

            return(messages);
        }
        public void DeleteFailNullArgument( )
        {
            Mock<INetworkOperations> mockNetworkOperations = new Mock<INetworkOperations>( );
            mockNetworkOperations.Setup( no => no.Read( ) ).Returns( "+OK" );

            Pop3Client pop3Client = new Pop3Client( mockNetworkOperations.Object );
            Assert.IsFalse( pop3Client.IsConnected );

            pop3Client.Connect( "SERVER", "USERNAME", "PASSWORD", true );
            Assert.IsTrue( pop3Client.IsConnected );

            pop3Client.Delete( null );
        }
        public void DeleteFailNotConnect( )
        {
            Mock<INetworkOperations> mockNetworkOperations = new Mock<INetworkOperations>( );
            mockNetworkOperations.Setup( no => no.Read( ) ).Returns( "+OK" );

            Pop3Client pop3Client = new Pop3Client( mockNetworkOperations.Object );
            Assert.IsFalse( pop3Client.IsConnected );

            pop3Client.Delete( new Pop3Message( ) { Number = 1 } );
        }
        public void DeleteOk( )
        {
            Mock<INetworkOperations> mockNetworkOperations = new Mock<INetworkOperations>( );
            mockNetworkOperations.Setup( no => no.Read( ) ).Returns( "+OK" );

            Pop3Client pop3Client = new Pop3Client( mockNetworkOperations.Object );
            Assert.IsFalse( pop3Client.IsConnected );

            pop3Client.Connect( "SERVER", "USERNAME", "PASSWORD", false );

            pop3Client.Delete( new Pop3Message( ) { Number = 1 } );
        }
Beispiel #9
0
        public static void MessageReceiptCycle()
        {
            Pop3Client popClient        = null;
            string     currentFromEmail = "";
            string     currentToEmail   = "";

            try
            {
                popClient = new Pop3Client();
                popClient.Connect(EmailAgent.Pop3EmailServer, EmailAgent.EmailUserName, EmailAgent.EmailPassword);
                List <Pop3Message> messages = popClient.List();
                int msgCount = 0;
                foreach (Pop3Message message in messages)
                {
                    msgCount++;
                    Console.WriteLine("Reading Msg: " + msgCount.ToString());
                    popClient.Retrieve(message);
                    string toPart   = message.To;
                    string fromPart = message.From;
                    Console.WriteLine("From: " + fromPart);
                    string body  = message.Body;
                    string b2    = System.Web.HttpUtility.HtmlDecode(body).Trim();
                    string msgID = Guid.NewGuid().ToString();

                    currentToEmail   = toPart;
                    currentFromEmail = fromPart;

                    string[] toArr   = currentToEmail.Split(new char[] { '[', ']', '{', '}', ';', '<', '>', ' ', ':', '"' }, StringSplitOptions.RemoveEmptyEntries);
                    string[] fromArr = currentFromEmail.Split(new char[] { '[', ']', '{', '}', ';', '<', '>', ' ', ':', '"' }, StringSplitOptions.RemoveEmptyEntries);

                    string toAddress   = null;
                    string fromAddress = null;

                    foreach (string s in toArr)
                    {
                        if (s.Contains("@") && s.Contains("."))
                        {
                            toAddress = s;
                            break;
                        }
                    }

                    foreach (string s in fromArr)
                    {
                        if (s.Contains("@") && s.Contains("."))
                        {
                            fromAddress = s;
                            break;
                        }
                    }

                    if (toAddress == null || fromAddress == null)
                    {
                        continue;
                    }

                    string senderQueue = SenderData + fromAddress + "\\";
                    if (!Directory.Exists(senderQueue))
                    {
                        Directory.CreateDirectory(senderQueue);
                    }
                    string msgQueue = senderQueue + toAddress + "\\";
                    if (!Directory.Exists(msgQueue))
                    {
                        Directory.CreateDirectory(msgQueue);
                    }
                    File.WriteAllText(msgQueue + msgID + ".txt", b2);
                    popClient.Delete(message);
                }
                Console.WriteLine("******************************");
                Console.WriteLine("Time: " + DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (popClient != null)
                {
                    popClient.Disconnect();
                }
            }
        }