从 Gmail C# 读取电子邮件 - IMAP

Reading Emails from Gmail C# - IMAP

我正在尝试阅读来自特定 Gmail 帐户的电子邮件。我在这里 (Whosebug) 找到了一些东西,但我无法阅读电子邮件。

这是我正在使用的:

 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();

    }

我遇到的问题可能发生在我第一次创建新的 ImapClient class 时。由于某种原因,它打开了一个浏览路径来选择一个文件(?)。 我很乐意提供一些帮助。 谢谢

如果您找到了一些东西,您应该使用主题的第二个 post 的解决方案,S22.Imap。 (Here你可以找到一个编译版本)。

下载后,您可以阅读文档。它简单易读。

实际上,我使用这个库并且效果很好!