This project is read-only.

Search results from Gmail

Topics: Help requests
Jan 15, 2014 at 10:41 PM
Hi, I use Gmail like this:

from:mailer-daemon@googlemail.com in:all

and I get more 1000 messages.

If I use this code using Imapx, I get 233 messages.
  var user = ServicioEnvioCorreo.Service1.USUARIO;
                var pass = ServicioEnvioCorreo.Service1.GOOGLE_ACCOUNT_APPLICATION_PASS; // PASSWORD_IMAP;
                using (var Client = new ImapClient("imap.gmail.com", 993, user, pass, AuthMethod.Login, true))
                {
                    uint[] uids = Client.Search(
                        SearchCondition.All().And(
                        SearchCondition.From("mailer-daemon@googlemail.com")
                        )
                        );

                    MailMessage[] messages = Client.GetMessages(uids);
                    Console.WriteLine(messages.Count());
Any suggestions?
Coordinator
Jan 16, 2014 at 9:08 AM
Hi kiquenet,

the above code has nothing to do with ImapX. It's for the S22.Imap client. However, in ImapX try the following:
var client = new ImapClient("imap.gmail.com", true);
if(client.Connect())
{
     if(client.Login(user, pass))
     {
           var msgs = client.Folders.All.Search("FROM \"mailer-daemon@googlemail.com\"");
           Console.WriteLine(messages.Count());
     }
}
Best regards,

Pavel
Jan 16, 2014 at 1:43 PM
Edited Jan 16, 2014 at 1:44 PM
Sorry Pavel.

Thx, it's great ImapX

Mabye many messages has a label. The target is get all messages from mailer-daemon, is right now using your code,

and another step get all messages from mailer-daemon and has a label.

Thanks.
Jan 17, 2014 at 7:27 PM
Now, it fails for me when I try use OR operator like this:
            var messages = client.Folders.All.Search("FROM \"mailer-daemon@googlemail.com\""
                            + " OR (FROM \"MAILER-DAEMON@yahoo.com\")"
                            + " OR (FROM \"postmaster@hotmail.com\")"
                            );
Coordinator
Jan 17, 2014 at 8:35 PM
Hi kiquenet,

try removing the surrounding braces.

For your question about labels, you need to use the X-GM-RAW extension, then you can use the extended search syntax for GMail.
var messages = client.Folders.All.Search("X-GM-RAW \"(from:MAILER-DAEMON@yahoo.com) OR (from:postmaster@hotmail.com) (label:mylabel)\"");
Greets,

Pavel