当前位置: 首页>>代码示例>>C#>>正文


C# Pop3Client.GetMessageCount方法代码示例

本文整理汇总了C#中OpenPop.Pop3.Pop3Client.GetMessageCount方法的典型用法代码示例。如果您正苦于以下问题:C# Pop3Client.GetMessageCount方法的具体用法?C# Pop3Client.GetMessageCount怎么用?C# Pop3Client.GetMessageCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenPop.Pop3.Pop3Client的用法示例。


在下文中一共展示了Pop3Client.GetMessageCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FetchAllMessages

		/// <summary>
		/// Example showing:
		///  - how to fetch all messages from a POP3 server
		/// </summary>
		/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
		/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
		/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
		/// <param name="username">Username of the user on the server</param>
		/// <param name="password">Password of the user on the server</param>
		/// <returns>All Messages on the POP3 server</returns>
		public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
		{
			// The client disconnects from the server when being disposed
			using(Pop3Client client = new Pop3Client())
			{
				// Connect to the server
				client.Connect(hostname, port, useSsl);

				// Authenticate ourselves towards the server
				client.Authenticate(username, password);

				// Get the number of messages in the inbox
				int messageCount = client.GetMessageCount();

				// We want to download all messages
				List<Message> allMessages = new List<Message>(messageCount);

				// Messages are numbered in the interval: [1, messageCount]
				// Ergo: message numbers are 1-based.
				// Most servers give the latest message the highest number
				for (int i = messageCount; i > 0; i--)
				{
					allMessages.Add(client.GetMessage(i));
				}

				// Now return the fetched messages
				return allMessages;
			}
		}
开发者ID:JoshKeegan,项目名称:hpop,代码行数:39,代码来源:Examples.cs

示例2: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            using (Pop3Client client = new Pop3Client())
            {
                //Para conectar no servidor do gmail use a porta 995 e SSL
                client.Connect("pop.gmail.com", 995, true);
                //Para conectar no servidor do hotmail use a porta 995 e SSL
                //client.Connect("pop3.live.com", 995, true);
                //usuário e senha para autenticar
                client.Authenticate("luisfelipe.lambert", "sakuda5G");
                //Pega o número de mensagens
                int messageCount = client.GetMessageCount();

                //Instanciar a lista 
                List<Message> mensagens = new List<Message>();
                //Pegar as mensagens
                for (int i = messageCount; i > 0; i--)
                {
                    //Adicionar a mensagem a lista
                    mensagens.Add(client.GetMessage(i));
                }
                //Popular o repeater com as mensagens
                repMensagens.DataSource = mensagens;
                repMensagens.DataBind();
            }
        }
        catch (Exception ex)
        {
            //Caso ocorra algum erro, uma mensagem será exibida na página
            litMensagemErro.Text = ex.ToString();
        }
    }
开发者ID:flviocarvalho,项目名称:conleg,代码行数:34,代码来源:Email.aspx.cs

示例3: Test

        public void Test()
        {
            const string hostName = "pop.gmail.com";
            int port = 995;
            bool useSsl = true;
            string userName = "USER";
            string password = "PASSWORD";

            using(Pop3Client client = new Pop3Client())
            {
                // Connect to the server
                client.Connect(hostName, port, useSsl);

                // Authenticate ourselves towards the server
                client.Authenticate(userName, password);

                // Get the number of messages in the inbox
                int messageCount = client.GetMessageCount();

                // We want to download all messages
                List<Message> allMessages = new List<Message>(messageCount);

                // Messages are numbered in the interval: [1, messageCount]
                // Ergo: message numbers are 1-based.
                // Most servers give the latest message the highest number
                for (int i = messageCount; i > 0; i--)
                {
                    allMessages.Add(client.GetMessage(i));
                }

                allMessages.ForEach(m=>Console.WriteLine("Display name: {0}", m.Headers.From.DisplayName));
            }
        }
开发者ID:constructor-igor,项目名称:TechSugar,代码行数:33,代码来源:Pop3ClientTests.cs

示例4: ReadAllEmails

        private void ReadAllEmails()
        {
            // The client disconnects from the server when being disposed
            using (Pop3Client client = new Pop3Client())
            {
                // Connect to the server
                client.Connect(EmailConfiguration.Pop3, EmailConfiguration.PopPort, true, 1800, 1800, removeCertificateCallback);

                // Authenticate ourselves towards the server
                client.Authenticate(EmailConfiguration.Email, EmailConfiguration.EmailPwd);

                // Get the number of messages in the inbox
                int messageCount = client.GetMessageCount();

                _systemLogger.Tell(string.Format("Total messages found: {0}", messageCount));

                // Most servers give the latest message the highest number
                for (int i = messageCount; i > 0; i--)
                {
                    var msg = client.GetMessage(i);

                    // Now return the fetched messages
                    _emailProcessorActor.Tell(new EmailMessage(){Subject = msg.Headers.Subject, Date = msg.Headers.Date});
                }
            }
        }
开发者ID:cpoDesign,项目名称:MailToTrello,代码行数:26,代码来源:EmailReaderActor.cs

示例5: GetAllMails

        /* Function to retrive Email from the POP3 Server */
        public void GetAllMails(object sender, DoWorkEventArgs e)
        {
            int percentComplete;

            using(Pop3Client client = new Pop3Client())
            {
                /* Set the Server, Port, ssl and username/password */
                client.Connect(Setting.Default.pop3_server, Setting.Default.pop3_port, Setting.Default.smtp_ssl);
                client.Authenticate(Setting.Default.username, Setting.Default.password);

                int messageCount = client.GetMessageCount();

                Debug.WriteLine(messageCount);

                /* Create a list to contain the messages */
                List<Message> allMessages = new List<Message>();

                /* A loop to calculate the progress of retriving the Emails  */
                for (int i = messageCount; i > 0; i--)
                {
                    allMessages.Add(client.GetMessage(i));
                    percentComplete = Convert.ToInt16((Convert.ToDouble(allMessages.Count) / Convert.ToDouble(messageCount)) * 100);
                    (sender as BackgroundWorker).ReportProgress(percentComplete);
                }
                e.Result =  allMessages;
            }
        }
开发者ID:Nicolai-,项目名称:CSharp_Mail_Client_New,代码行数:28,代码来源:POPClient.cs

示例6: FetchAllMessages

        public void FetchAllMessages()
        {
            // The client disconnects from the server when being disposed
            using (Pop3Client client = new Pop3Client())
            {
                // Connect to the server
                client.Connect(_hostName, _port, true);

                // Authenticate ourselves towards the server
                client.Authenticate(_username, _password);

                // Get the number of messages in the inbox
                int messageCount = client.GetMessageCount();

                // We want to download all messages
                List<Message> allMessages = new List<Message>(messageCount);

                // Messages are numbered in the interval: [1, messageCount]
                // Ergo: message numbers are 1-based.
                for (int i = 1; i <= messageCount; i++)
                {
                    allMessages.Add(client.GetMessage(i));
                }
            }
        }
开发者ID:macki,项目名称:razem,代码行数:25,代码来源:EmailManager.cs

示例7: fetchAllMessages

        private static void fetchAllMessages(object sender, DoWorkEventArgs e)
        {
            int percentComplete;

            // The client disconnects from the server when being disposed
            using (Pop3Client client = new Pop3Client())
            {
                // Connect to the server
                //client.Connect("pop.gmail.com", 995, true);
                client.Connect("mail1.stofanet.dk", 110, false);

                // Authenticate ourselves towards the server
                client.Authenticate("2241859m002", "big1234");

                // Get the number of messages in the inbox
                int messageCount = client.GetMessageCount();

                // We want to download all messages
                List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);

                // Messages are numbered in the interval: [1, messageCount]
                // Ergo: message numbers are 1-based.
                // Most servers give the latest message the highest number

                for (int i = messageCount; i > 0; i--)
                {
                    allMessages.Add(client.GetMessage(i));
                    percentComplete = Convert.ToInt16((Convert.ToDouble(allMessages.Count) / Convert.ToDouble(messageCount)) * 100);
                    (sender as BackgroundWorker).ReportProgress(percentComplete);
                }

                // Now return the fetched messages
                e.Result = allMessages;
            }
        }
开发者ID:Graungaard,项目名称:ProgrammeringIII-EmailClient,代码行数:35,代码来源:RecieveMail.cs

示例8: ImportEmails

        //-------------------------------------------------------------------------------------------
        private void ImportEmails(Communication_EmailAccounts account)
        {
            Console.WriteLine("Importing e-mails for " + account.Id + " -- " + account.Host);
               using (Pop3Client client = new Pop3Client())
               {
                    // connect
                    client.Connect(account.Host, account.Port, (account.Type == "pops"));
                    client.Authenticate(account.Username, account.Password);

                    // iterate over the messages
                    int messageCount = client.GetMessageCount();
                    List<Message> allMessages = new List<Message>(messageCount);
                    for (int i = 1; i <= messageCount; i++)
                    {
                         using (WeavverEntityContainer data = new WeavverEntityContainer())
                         {
                              //data.SearchAllTables("asdf");
                              // save to database
                              Message m = (Message) client.GetMessage(i);
                              if (m.MessagePart.IsText)
                              {
                                   Communication_Emails item = new Communication_Emails();
                                   item.From = m.Headers.From.Raw;
                                   item.Subject = m.Headers.Subject;
                                   item.Raw = System.Text.ASCIIEncoding.ASCII.GetString(m.RawMessage);
                                   data.SaveChanges();

                                   client.DeleteMessage(i);
                              }
                         }
                    }
               }
        }
开发者ID:weavver,项目名称:data,代码行数:34,代码来源:Communication_Email.cs

示例9: GetAllMessages

        //Connect to gmail, get emails and ad it to a MessageList
        public static List<OpenPop.Mime.Message> GetAllMessages(string hostname, int port, bool ssl, string username, string password)
        {
            try
            {
                Pop3Client client = new Pop3Client();

                    if (client.Connected)
                    {
                        client.Disconnect();
                    }

                    client.Connect(hostname, port, ssl);
                    client.Authenticate(username, password);

                    int messageCount = client.GetMessageCount();

                    List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);

                    for (int i = messageCount; i > messageCount - 5; i--)
                    {
                        allMessages.Add(client.GetMessage(i));
                    }

                    return allMessages;
                }

            catch(Exception ex)
            {
                MessageBox.Show("You have written username or password wrong or something else has happened! Program will not keep going, please open it again, thank you : " + ex.Message);
                Thread.CurrentThread.Abort();
                //EmailClient.
            }

            return null;
        }
开发者ID:kayabirch,项目名称:H5Email,代码行数:36,代码来源:LogedIn.cs

示例10: GetMessages

        public IEnumerable<MessageDTO> GetMessages(string hostname, int port, bool useSsl, string username,
                                                   string password, int? maxNumber = null)
        {
            var allMessages = new List<MessageDTO>();

            try
            {
                // The client disconnects from the server when being disposed
                using (var client = new Pop3Client())
                {
                    client.Connect(hostname, port, useSsl);

                    client.Authenticate(username, password, AuthenticationMethod.UsernameAndPassword);

                    var maxCount = client.GetMessageCount();

                    //work out subset to take from messages
                    var messageCount = (maxNumber.HasValue && maxNumber < maxCount) ? (maxCount - maxNumber.Value) : 0;

                    //message list is 1 based
                    //loop written backwards so messages are in correct order
                    for (var i = maxCount; i > messageCount; i--)
                    {
                        var currentMessage = client.GetMessage(i);
                        var html = currentMessage.FindFirstHtmlVersion();

                        allMessages.Add(new MessageDTO
                            {
                                Body =
                                    html != null && html.Body != null
                                        ? Encoding.UTF8.GetString(html.Body)
                                        : string.Empty,
                                DateSent = currentMessage.Headers.DateSent,
                                DisplayName = currentMessage.Headers.From.DisplayName,
                                From = currentMessage.Headers.From.Address,
                                Id = currentMessage.Headers.MessageId,
                                Subject = currentMessage.Headers.Subject,
                                Uid = currentMessage.Headers.MessageId
                            });

                    }

                }
            }
            catch (Exception ex)
            {
                var path = Path.GetTempPath();
                var stream = File.OpenWrite(Path.Combine(path, "mailFireErrorLog.log"));

                using (var fileWriter = new StreamWriter(stream))
                {
                    fileWriter.Write(string.Format("Exception occurred: {0} - at {1}", ex.Message, DateTime.Now));
                }
            }
            return allMessages;
        }
开发者ID:James84,项目名称:MailFire,代码行数:56,代码来源:OpenPop3Messaging.cs

示例11: DownloadMailsAndPushToIssueTracker

        private static void DownloadMailsAndPushToIssueTracker()
        {
            var host = Settings.Get("Pop3Host", "");
            var port = Settings.Get("Pop3Port", 110);
            var useSsl = Settings.Get("Pop3UseSsl", false);
            var username = Settings.Get("Pop3Username", "");
            var password = Settings.Get("Pop3Password", "");

            if (host.IsNoE())
            {
                Console.WriteLine("\tNo Pop3Host specified.");
                LogOwnError(new ApplicationException("No Pop3Host specified."));
                return;
            }

            try
            {
                Console.WriteLine("\tConnecting to POP3 server {0}:{1} ({4}) using {2} / {3} ...", host, port, username, password, useSsl ? "SSL" : "no SSL");

                using (var pop3Client = new Pop3Client())
                {
                    pop3Client.Connect(host, port, useSsl);
                    if (username.HasValue())
                        pop3Client.Authenticate(username, password);

                    Console.WriteLine("\tFetching message count ...");
                    var messageCount = pop3Client.GetMessageCount();

                    for (var i = 1; i <= messageCount; i++)
                    {
                        try
                        {
                            Console.WriteLine("\tFetching message {0} / {1} ...", i, messageCount);
                            var message = pop3Client.GetMessage(i);

                            if (PushToIssueTracker(message))
                                pop3Client.DeleteMessage(i);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("\tUnable to fetch or push message: " + ex);
                            LogOwnError(new ApplicationException("Unable to fetch or push message: " + ex.Message, ex));
                        }
                    }

                    pop3Client.Disconnect();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\tUnable to download mails: " + ex);
                LogOwnError(new ApplicationException("Unable to download mails: " + ex.Message, ex));
            }
        }
开发者ID:saxx,项目名称:IssueTracker,代码行数:54,代码来源:Program.cs

示例12: GetPopEmail

 private static GetEmailResponse GetPopEmail()
 {
     var client = new Pop3Client();
     client.Connect("pop.gmail.com", 995, true);
     client.Authenticate("[email protected]", "Woq0wy951", AuthenticationMethod.UsernameAndPassword);
     var count = client.GetMessageCount();
     var message = client.GetMessage(count);
     Console.WriteLine(message.Headers.Subject);
     return new GetEmailResponse
     {
     };
 }
开发者ID:cberberian,项目名称:Brain,代码行数:12,代码来源:EmailHandler.cs

示例13: GetNewMessages

        private static List<Message> GetNewMessages(Pop3Client pop3Client)
        {
            var allMessages = new List<Message>();

            pop3Client.Connect(Hostname, Port, UseSsl);
            pop3Client.Authenticate(Username, Password);
            var messageCount = pop3Client.GetMessageCount();

            for (var i = messageCount; i > 0; i--)
            {
                allMessages.Add(pop3Client.GetMessage(i));
            }
            return allMessages;
        }
开发者ID:petermunnings,项目名称:funwithoiky,代码行数:14,代码来源:Program.cs

示例14: Retrieve

        public void Retrieve()
        {
            var messages = new List<Message>();
            using (var client = new Pop3Client())
            {
                var appSettings = ConfigurationManager.AppSettings;
                client.Connect(appSettings["host"], 110, false);
                client.Authenticate(appSettings["user"], appSettings["pass"], AuthenticationMethod.UsernameAndPassword);
                for (var i = client.GetMessageCount(); i > 0; i--)
                {
                    var message = client.GetMessage(i);
                    messages.Add(message);
            #if (!DEBUG)
                    client.DeleteMessage(i);
            #endif
                }
            }

            _parser.Parse(messages);
        }
开发者ID:Grinderofl,项目名称:ImageHosting,代码行数:20,代码来源:EmailRetriever.cs

示例15: DeleteMessageByMessageId

		/// <summary>
		/// Example showing:
		///  - how to delete fetch an emails headers only
		///  - how to delete a message from the server
		/// </summary>
		/// <param name="client">A connected and authenticated Pop3Client from which to delete a message</param>
		/// <param name="messageId">A message ID of a message on the POP3 server. Is located in <see cref="MessageHeader.MessageId"/></param>
		/// <returns><see langword="true"/> if message was deleted, <see langword="false"/> otherwise</returns>
		public bool DeleteMessageByMessageId(Pop3Client client, string messageId)
		{
			// Get the number of messages on the POP3 server
			int messageCount = client.GetMessageCount();

			// Run trough each of these messages and download the headers
			for (int messageItem = messageCount; messageItem > 0; messageItem--)
			{
				// If the Message ID of the current message is the same as the parameter given, delete that message
				if (client.GetMessageHeaders(messageItem).MessageId == messageId)
				{
					// Delete
					client.DeleteMessage(messageItem);
					return true;
				}
			}

			// We did not find any message with the given messageId, report this back
			return false;
		}
开发者ID:JoshKeegan,项目名称:hpop,代码行数:28,代码来源:Examples.cs


注:本文中的OpenPop.Pop3.Pop3Client.GetMessageCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。