Beispiel #1
0
        static void Run()
        {
            // ExStart: ListingMessagesWithPagingSupport
            ///<summary>
            /// This example shows the paging support of ImapClient for listing messages from the server
            /// Available in Aspose.Email for .NET 6.4.0 and onwards
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                try
                {
                    int         messagesNum  = 12;
                    int         itemsPerPage = 5;
                    MailMessage message      = null;
                    // Create some test messages and append these to server's inbox
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35157 - " + Guid.NewGuid(),
                            "EMAILNET-35157 Move paging parameters to separate class");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    // List messages from inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages();
                    // Verify the number of messages added
                    Console.WriteLine(totalMessageInfoCol.Count);

                    ////////////////// RETREIVE THE MESSAGES USING PAGING SUPPORT////////////////////////////////////

                    List <ImapPageInfo> pages        = new List <ImapPageInfo>();
                    PageSettings        pageSettings = new PageSettings();
                    ImapPageInfo        pageInfo     = client.ListMessagesByPage(itemsPerPage, 0, pageSettings);
                    Console.WriteLine(pageInfo.TotalCount);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(itemsPerPage, pageInfo.NextPage.PageOffset, pageSettings);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                    {
                        retrievedItems += folderCol.Items.Count;
                    }
                    Console.WriteLine(retrievedItems);
                }
                finally
                {
                }
            }
            // ExEnd: ListingMessagesWithPagingSupport
        }
Beispiel #2
0
        public static void Run()
        {
            // ExStart:1
            ImapClient imapClient = new ImapClient();

            imapClient.Host                = "<HOST>";
            imapClient.Port                = 993;
            imapClient.Username            = "******";
            imapClient.Password            = "******";
            imapClient.SupportedEncryption = EncryptionProtocols.Tls;
            imapClient.SecurityOptions     = SecurityOptions.SSLImplicit;

            PageSettings pageSettings = new PageSettings {
                AscendingSorting = false
            };
            ImapPageInfo pageInfo = imapClient.ListMessagesByPage(5, pageSettings);
            ImapMessageInfoCollection messages = pageInfo.Items;

            foreach (ImapMessageInfo message in messages)
            {
                Console.WriteLine(message.Subject + " -> " + message.Date.ToString());
            }
            // ExEnd:1
        }
        static void Run()
        {
            // ExStart:SearchWithPagingSupport
            ///<summary>
            /// This example shows how to search for messages using ImapClient of the API with paging support
            /// Introduced in Aspose.Email for .NET 6.4.0
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 84, "username", "password"))
            {
                try
                {
                    // Append some test messages
                    int         messagesNum  = 12;
                    int         itemsPerPage = 5;
                    MailMessage message      = null;
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35128 - " + Guid.NewGuid(),
                            "111111111111111");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }
                    string body = "2222222222222";
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35128 - " + Guid.NewGuid(),
                            body);
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    ImapQueryBuilder iqb = new ImapQueryBuilder();
                    iqb.Body.Contains(body);
                    MailQuery query = iqb.GetQuery();

                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages(query);
                    Console.WriteLine(totalMessageInfoCol.Count);

                    //////////////////////////////////////////////////////

                    List <ImapPageInfo> pages    = new List <ImapPageInfo>();
                    ImapPageInfo        pageInfo = client.ListMessagesByPage(ImapFolderInfo.InBox, query, itemsPerPage);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(ImapFolderInfo.InBox, query, pageInfo.NextPage);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                    {
                        retrievedItems += folderCol.Items.Count;
                    }
                }
                finally
                {
                }
            }
            // ExEnd: SearchWithPagingSupport
        }