Example #1
0
        public static void Run()
        {
            // ExStart:RetrieveMessagesAsynchronously
            Pop3Client client = new Pop3Client();

            client.Host            = "pop.gmail.com";
            client.Port            = 995;
            client.SecurityOptions = SecurityOptions.SSLImplicit;
            client.Username        = "******";
            client.Password        = "******";

            try
            {
                Pop3MessageInfoCollection messages = client.ListMessages();
                Console.WriteLine("Total Number of Messages in inbox:" + messages.Count);
                AutoResetEvent evnt     = new AutoResetEvent(false);
                MailMessage    message  = null;
                AsyncCallback  callback = delegate(IAsyncResult ar)
                {
                    message = client.EndFetchMessage(ar);
                    evnt.Set();
                };
                client.BeginFetchMessage(messages[0].SequenceNumber, callback, null);
                evnt.WaitOne();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:RetrieveMessagesAsynchronously
        }