public static void Run()
        {
            // Connect and log in to IMAP
            const string host     = "host";
            const int    port     = 143;
            const string username = "******";
            const string password = "******";
            ImapClient   client   = new ImapClient(host, port, username, password);

            try
            {
                client.SelectFolder("Inbox");

                // ExStart:SpecifyEncodingForQueryBuilder
                // Set conditions
                ImapQueryBuilder builder = new ImapQueryBuilder(Encoding.UTF8);
                builder.Subject.Contains("ğüşıöç", true);
                MailQuery query = builder.GetQuery();
                // ExEnd:SpecifyEncodingForQueryBuilder

                // Get list of messages
                ImapMessageInfoCollection messages = client.ListMessages(query);
                foreach (ImapMessageInfo info in messages)
                {
                    Console.WriteLine("Message Id: " + info.MessageId);
                }

                // Disconnect from IMAP
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            // ExStart:FilteringMessagesFromIMAPMailbox
            // Connect and log in to IMAP
            const string host     = "host";
            const int    port     = 143;
            const string username = "******";
            const string password = "******";
            ImapClient   client   = new ImapClient(host, port, username, password);

            client.SelectFolder("Inbox");
            // Set conditions, Subject contains "Newsletter", Emails that arrived today
            ImapQueryBuilder builder = new ImapQueryBuilder();

            builder.Subject.Contains("Newsletter");
            builder.InternalDate.On(DateTime.Now);
            // Build the query and Get list of messages
            MailQuery query = builder.GetQuery();
            ImapMessageInfoCollection messages = client.ListMessages(query);

            Console.WriteLine("Imap: " + messages.Count + " message(s) found.");
            // Disconnect from IMAP
            client.Dispose();
            // ExEnd:FilteringMessagesFromIMAPMailbox
        }
        public static void Run()
        {
            // ExStart:InternalDateFilter
            // Connect and log in to IMAP
            const string host = "host";
            const int port = 143;
            const string username = "******";
            const string password = "******";
            ImapClient client = new ImapClient(host, port, username, password);
            client.SelectFolder("Inbox");

            // Set conditions, Subject contains "Newsletter", Emails that arrived today
            ImapQueryBuilder builder = new ImapQueryBuilder();
            builder.Subject.Contains("Newsletter");
            builder.InternalDate.On(DateTime.Now);
            // Build the query and Get list of messages
            MailQuery query = builder.GetQuery();
            ImapMessageInfoCollection messages = client.ListMessages(query);
            foreach (ImapMessageInfo info in messages)
            {
                Console.WriteLine("Internal Date: " + info.InternalDate);
            }
            // Disconnect from IMAP
            client.Dispose();
            // ExEnd:InternalDateFilter
        }
        public static void Run()
        {
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, port and SecurityOptions for your client
            client.Host            = "imap.gmail.com";
            client.Username        = "******";
            client.Password        = "******";
            client.Port            = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                // ExStart:ListMessagesAsynchronouslyWithMailQuery
                ImapQueryBuilder builder = new ImapQueryBuilder();
                builder.Subject.Contains("Subject");
                MailQuery    query                 = builder.GetQuery();
                IAsyncResult asyncResult           = client.BeginListMessages(query);
                ImapMessageInfoCollection messages = client.EndListMessages(asyncResult);
                // ExEnd:ListMessagesAsynchronouslyWithMailQuery

                Console.WriteLine("New Message Added Successfully");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
        }
Ejemplo n.º 5
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;

            ImapQueryBuilder imapQueryBuilder = new ImapQueryBuilder();

            imapQueryBuilder.HasNoFlags(ImapMessageFlags.IsRead); /* get unread messages. */
            MailQuery query = imapQueryBuilder.GetQuery();

            imapClient.ReadOnly = true;
            imapClient.SelectFolder("Inbox");
            ImapMessageInfoCollection messageInfoCol = imapClient.ListMessages(query);

            Console.WriteLine("Initial Unread Count: " + messageInfoCol.Count());
            if (messageInfoCol.Count() > 0)
            {
                imapClient.FetchMessage(messageInfoCol[0].SequenceNumber);

                messageInfoCol = imapClient.ListMessages(query);
                // This count will be equal to the initial count
                Console.WriteLine("Updated Unread Count: " + messageInfoCol.Count());
            }
            else
            {
                Console.WriteLine("No unread messages found");
            }
            //ExEnd: 1

            Console.WriteLine("ImapReadOnlyMode executed successfully.");
        }
        public static void Run()
        {
            // Connect and log in to IMAP
            const string host     = "host";
            const int    port     = 143;
            const string username = "******";
            const string password = "******";
            ImapClient   client   = new ImapClient(host, port, username, password);

            try
            {
                client.SelectFolder("Inbox");

                // ExStart:CaseSensitiveEmailsFiltering
                // Set conditions, Subject contains "Newsletter", Emails that arrived today
                ImapQueryBuilder builder = new ImapQueryBuilder();
                builder.Subject.Contains("Newsletter", true);
                builder.InternalDate.On(DateTime.Now);
                MailQuery query = builder.GetQuery();
                // ExEnd:CaseSensitiveEmailsFiltering

                // Get list of messages
                ImapMessageInfoCollection messages = client.ListMessages(query);
                foreach (ImapMessageInfo info in messages)
                {
                    Console.WriteLine("Message Id: " + info.MessageId);
                }

                // Disconnect from IMAP
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 7
0
        private void linkLabelAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (comboBoxFields.SelectedItem == null || comboBoxOperand.SelectedItem == null)
            {
                return;
            }

            if (String.IsNullOrWhiteSpace(textBoxValue.Text) && !(comboBoxOperand.Text == "Empty" || comboBoxOperand.Text == "Not Empty"))
            {
                return;
            }

            switch ((String)comboBoxFields.SelectedItem)
            {
            case "Bcc":
                ProcessStringComparisonField(query.Bcc);
                break;

            case "Body":
                ProcessStringComparisonField(query.Body);
                break;

            case "Cc":
                ProcessStringComparisonField(query.Cc);
                break;

            case "From":
                ProcessStringComparisonField(query.From);
                break;

            case "Message ID":
                ProcessStringComparisonField(query.MessageId);
                break;

            case "Subject":
                ProcessStringComparisonField(query.Subject);
                break;

            case "Text":
                ProcessStringComparisonField(query.Text);
                break;

            case "To":
                ProcessStringComparisonField(query.To);
                break;

            case "Internal Date":
                ProcessDateComparisonField(query.InternalDate);
                break;

            case "Sent Date":
                ProcessDateComparisonField(query.SentDate);
                break;

            case "Message Size":
                ProcessIntComparisonField(query.MessageSize);
                break;
            }

            textBoxQuery.Text = query.GetQuery().ToString();

            comboBoxFields.SelectedItem  = null;
            comboBoxOperand.SelectedItem = null;
            textBoxValue.Text            = null;
        }
        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
        }
        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
        }