imap search message

0 votes
asked Aug 18, 2014 by turissssst (200 points)
edited Aug 20, 2014

how can I implement in your project search messages by Imap and output them in any number of variable?

Applies to: Rebex Secure Mail
commented Aug 18, 2014 by Tomas Knopp (58,890 points)
edited Aug 20, 2014

I am sorry I do not understand your requirements - could you please be more specific? You might also want to have a look at our IMAP tutorials as well as our IMAP samples which are part of the Rebex Secure Mail package - namely IMAP GUI Browser, IMAP Console Client and IMAP Downloader.

commented Aug 19, 2014 by turissssst (200 points)
edited Aug 20, 2014

I want to search for posts by Imap but do not know how to display the count

4 Answers

0 votes
answered Aug 19, 2014 by Tomas Knopp (58,890 points)
edited Aug 19, 2014

You can display the messages count on the IMAP server Inbox folder with this code snippet:

Imap client = new Imap();
client.Connect("test.rebex.net");
client.Login("demo", "password");

client.SelectFolder("Inbox");
//count of total and unread messages is accessible directly through a property:
Console.WriteLine("Total messages count: {0}", client.CurrentFolder.TotalMessageCount);
Console.WriteLine("Unread messages count: {0}", client.CurrentFolder.NotSeenMessageCount);
client.Disconnect();
0 votes
answered Aug 19, 2014 by turissssst (200 points)
edited Aug 20, 2014

example I want to find a letter from rebex via Imap. I then display the number of letters found?

commented Aug 19, 2014 by Tomas Knopp (58,890 points)
edited Aug 19, 2014

The following code snippet finds messages which were sent by support@rebex.net and then shows their count:

Imap client = new Imap();
client.Connect("imap.gmail.com", SslMode.Implicit);
client.Login("user@gmail.com", "password");

client.SelectFolder("Inbox");

// find messages from "support@rebex.net"
ImapMessageCollection fromRebex = client.Search
(
    ImapSearchParameter.From("support@rebex.net")
);

Console.WriteLine("There are {0} messages from 'support@rebex.net'", fromRebex.Count);

client.Disconnect();
commented Aug 20, 2014 by turissssst (200 points)
edited Aug 20, 2014

Thank you very much!

0 votes
answered Aug 20, 2014 by turissssst (200 points)
edited Aug 20, 2014
try
        {
            Imap clientt = new Imap();
            clientt.Connect("imap.yandex.ru");
            clientt.Login("elseeker@yandex.ru", "******");
            clientt.SelectFolder("Inbox");


            // find messages from "support@rebex.net"
            ImapMessageCollection fromRebex = clientt.Search
            (
                ImapSearchParameter.From("embarcadero.com")
            );
            MessageBox.Show("2");
            MessageBox.Show("messages " + fromRebex.Count);
            //  Console.WriteLine("There are {0} messages from 'support@rebex.net'", fromRebex.Count);

          //  clientt.Disconnect();
        }
        catch { MessageBox.Show("error"); }

error!

0 votes
answered Aug 20, 2014 by Tomas Knopp (58,890 points)
edited Aug 20, 2014

Please modify your code to log into the logwriter like this and send us the created log as well as content of the ex.ToString():

    try
    {
        Imap clientt = new Imap();
        clientt.LogWriter = new Rebex.FileLogWriter(@"c:\temp\log.txt", Rebex.LogLevel.Debug);

        clientt.Connect("imap.yandex.ru");
        clientt.Login("elseeker@yandex.ru", "******");
        clientt.SelectFolder("Inbox");

        ImapMessageCollection fromRebex = clientt.Search
        (
            ImapSearchParameter.From("embarcadero.com")
        );
        MessageBox.Show("2");
        MessageBox.Show("messages " + fromRebex.Count);
    }
    catch (Exception ex){ MessageBox.Show(ex.ToString()); }

Seeing the log would enable us to see what is going on and help you solve this issue.

...