1

I'm trying to read emails from specific Gmail account. I have found something here(Stackoverflow) but I can't manage reading the emails.

this is what I'm using:

 public static void logingmail()
    {
        // Connect to the IMAP server. The 'true' parameter specifies to use SSL
        // which is important (for Gmail at least)
        ImapClient ic = new ImapClient("imap.gmail.com", "Any@gmail.com", "4521945219",AuthMethods.Login, 993, true);
        // Select a mailbox. Case-insensitive
        ic.SelectMailbox("Inbox");
       string countmessages = ic.GetMessageCount().ToString();
        // Get the first *11* messages. 0 is the first message;
        // and it also includes the 10th message, which is really the eleventh ;)
        // MailMessage represents, well, a message in your mailbox
        MailMessage[] mm = ic.GetMessages(0, 10);
        foreach (MailMessage m in mm)
        {

            var subject = m.Subject.ToString();
        }
        // Probably wiser to use a using statement
        ic.Dispose();

    }

The problem I'm experiencsing probably happening when I'm first creating the new ImapCliient class. for some reason it's opening a browse path to choose a file(?). I'll be happy for some assistance. Thanks

JumpIntoTheWater
  • 1,306
  • 2
  • 19
  • 46
  • This file browser dialog appearing is strange. Have you tryed to debug this method? on what line this dialog appears? And wrap your method in try-catch block, maybe there is an unhandled exception is thrown – Fragment Feb 18 '16 at 08:15
  • Strange indeed. It happens on the first line. ImapClient ic= new ImapClient(......); I have tried debugging it. But I will add try and catch wrap – JumpIntoTheWater Feb 18 '16 at 08:23
  • Possible duplicate of [using c# .net librarires to check for IMAP messages from gmail servers](http://stackoverflow.com/questions/545724/using-c-sharp-net-librarires-to-check-for-imap-messages-from-gmail-servers) – Fragment Feb 18 '16 at 08:36

1 Answers1

1

You should use the solution of the second post of the topic were you have found something, S22.Imap. (Here you can find a compiled version).

After download, you can read the documentation. It is simple and readable.

Actually, I use this library and that works well !

Korback
  • 26
  • 3