Ejemplo n.º 1
0
        public static MailBee.Mime.MailMessage Pop3ReceiveEmail()
        {
            try
            {
                MailBee.Pop3Mail.Pop3 pop3 = new MailBee.Pop3Mail.Pop3();
                pop3.Log.Enabled  = true;
                pop3.Log.Filename = @"F:\DevProject\MailTestDemo\log.txt";

                if (!pop3.IsConnected)
                {
                    bool ifConnect = pop3.Connect("pop3.126.com", 110);
                }
                if (!pop3.IsLoggedIn)
                {
                    bool ifLogin = pop3.Login("frankfeng23", "Aa00000000");
                }

                int count = pop3.InboxMessageCount;
                //MailBee.Mime.MailMessageCollection emails = pop3.DownloadEntireMessages(count-6,5);
                return(pop3.DownloadEntireMessage(-1));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public static void Pop3ReceiveEmail()
        {
            try
            {
                MailBee.Pop3Mail.Pop3 pop3 = new MailBee.Pop3Mail.Pop3();
                Pop3.LicenseKey   = "MN110-9E565627568556335608A32D4F47-FC3B";// "MN110-BD758AFA74AB752575128ACF6CAE-EEE7";
                pop3.Log.Enabled  = true;
                pop3.Log.Filename = @"log.txt";

                if (!pop3.IsConnected)
                {
                    pop3.Timeout = 10000;
                    //bool ifConnect = pop3.Connect("pop.gmail.com", 995);
                    //bool ifConnect = pop3.Connect("pop.163.com", 995);
                    //bool ifConnect = pop3.Connect("pop.126.com", 995);
                    //pop3.SslMode = MailBee.Security.SslStartupMode.OnConnect;
                    bool ifConnect = pop3.Connect("outlook.office365.com", 995);
                }
                if (!pop3.IsLoggedIn)
                {
                    //bool ifLogin = pop3.Login("*****@*****.**", "dcsrbisbxztxqqru");
                    //bool ifLogin = pop3.Login("*****@*****.**", "fcf.1130,gmail");
                    //bool ifLogin = pop3.Login("*****@*****.**", "cmljyggwcswhwlsz", MailBee.AuthenticationMethods.Auto, MailBee.AuthenticationOptions.PreferSimpleMethods, null);
                    //bool ifLogin = pop3.Login("*****@*****.**", "fcf.1130,126");
                    bool ifLogin = pop3.Login("*****@*****.**", "Weisheng0409", MailBee.AuthenticationMethods.Auto, MailBee.AuthenticationOptions.PreferSimpleMethods, null);
                }
                int total = pop3.InboxMessageCount;
                var ids   = pop3.GetMessageUids();
                Console.WriteLine("Ids length: " + ids.Length);

                Console.WriteLine($"inbox count: {total}");
                //var lastMail = pop3.DownloadEntireMessage(-1);
                //Print(lastMail, 1);
                //Console.WriteLine($"*********************************************************");
                int number     = 20;
                int count      = total >= number ? number : total; //如果少于100封信,则取全部,如果大于100封信,则取最新的100封。
                int beginIndex = count == number ? (total - number) : 1;
                //MailBee.Mime.MailMessageCollection emails = pop3.DownloadEntireMessages(beginIndex, count);

                //int index = 1;
                //foreach (MailMessage mail in emails)
                //{
                //    Print(mail, index);
                //    index += 1;
                //}

                foreach (var uid in ids.Take(100))
                {
                    var mail = pop3.DownloadEntireMessage(pop3.GetMessageIndexFromUid(uid));
                    Print(mail, 0, uid);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }