This project is read-only.

How to Search The Particular Keyword From the Specified Email Address

May 15, 2013 at 3:32 AM
Hey This is the Awesome Library With Perfect Sample application thanxx a Lot Man...
Superb Job..

Now my Problem Is That
I Want to Search a Keyword

Suppose "Shutdown"
from the My All Email Whose Email Address is "Youremail@gmail.com" Specified Email Address
I want Only Keyword if it Present or Not

how to do that ??
Coordinator
May 15, 2013 at 4:20 PM
Hi hiral2cool,

the search command can be very individual, if you want to filter the messages by a specific sender and a keyword contained, it looks the following way:
SEARCH FROM "name@domain.com" TEXT "keyword"
A full list of supported parameters for the serach command can be found in the specification: http://tools.ietf.org/html/rfc3501#section-6.4.4
Some servers, like GMail may also offer extended syntax.

If you need help implementing a command, feel free to ask here.


Best regards.

Pavel Azanov
May 15, 2013 at 11:22 PM
Edited May 15, 2013 at 11:57 PM
ok got it.... but where...it is write in my code ??
means in where

ya i want to use only Gmail Account to Search How to fire Query
Please tell me. ......
Coordinator
May 16, 2013 at 2:08 PM
Edited May 17, 2013 at 3:50 PM
I put a small sample together for you to get started:
string emailServer = "imap.gmail.com";
string email = "name@googlemail.com";
string pass = "password";
bool isUseSsl = true;
int port = 993;
SslProtocols protocol = SslProtocols.Default;

ImapClient imapClient = new ImapClient(emailServer, port, isUseSsl, protocol);

if (imapClient.Connection())
{
    bool isLogged = imapClient.LogIn(email, pass);
    if (isLogged)
    {
        Folder folder = imapClient.Folders["INBOX"];
        MessageCollection messages = folder.Search("FROM \"name@domain.com\" TEXT \"keyword\"", true);

        // ...

    }
}
I also recommend you to take a look at the sample application, as many features of the library are shown there.
May 17, 2013 at 12:29 PM
Program.ImapClient = new ImapClient(_host, _port, _useSSL, _selectedProtocol);
            if (Program.ImapClient.Connection())
            {

                if (Program.ImapClient.LogIn(_login, _pass))
                {
                    e.Result = true;
                    Folder folder = Program.ImapClient.Folders["INBOX"];
                    MessageCollection messages = folder.Search("SEARCH FROM \"hiral2spy@gmail.com\" TEXT \"youtube\"", true);
                }
                else
                    _result = "Failed to login";
            }

here it is give the Error Bad Input Query...
i am very Nearer to My Goal...
Please help me..

i give here one Sample Input query
is this correct or not
what is the Problem ????
Coordinator
May 17, 2013 at 3:50 PM
Hi,

sorry for my mistake, if you call the command, you don't have to include the "SEARCH" term inside. Here is the correct code once again:
string emailServer = "imap.gmail.com";
string email = "name@googlemail.com";
string pass = "password";
bool isUseSsl = true;
int port = 993;
SslProtocols protocol = SslProtocols.Default;

ImapClient imapClient = new ImapClient(emailServer, port, isUseSsl, protocol);

if (imapClient.Connection())
{
    bool isLogged = imapClient.LogIn(email, pass);
    if (isLogged)
    {
        Folder folder = imapClient.Folders["INBOX"];
        MessageCollection messages = folder.Search("FROM \"name@domain.com\" TEXT \"keyword\"", true);

        // ...

    }
}
Kind regards,

Pavel Azanov