【问题标题】:EAGetMail, How to read all emails from POP3 Gmail server?EAGetMail,如何从 POP3 Gmail 服务器读取所有电子邮件?
【发布时间】:2013-05-19 00:28:06
【问题描述】:

我正在使用 EAGetMail 库来阅读来自 Gmail 的电子邮件。 这是我的代码:

    private void readMails(){
        MailServer oServer=new MailServer("pop.gmail.com", "something@gmail.com", "noneedtoseethis", ServerProtocol.Pop3);
        MailClient oClient = new MailClient("Client");
        oServer.SSLConnection = true;
        oServer.Port = 995;
        try {
            oClient.Connect(oServer);
            MailInfo[] infos = oClient.GetMailInfos();
            Console.WriteLine(infos.Length);
            for (int i = 0; i < infos.Length; i++){
                MailInfo info = infos[i];
                Mail oMail = oClient.GetMail(info);

                Console.WriteLine("From: {0}", oMail.From.ToString());
                //oClient.Delete(info);
            }
            oClient.Quit();
        } catch (Exception ep) {
            Console.WriteLine(ep.Message);
        }
    }

虽然它似乎唯一收到的是我收到的新消息
每五分钟有 2 或 3 条。

但我想阅读收件箱中的所有电子邮件,而不仅仅是新邮件
我怎样才能做到这一点?

【问题讨论】:

    标签: c# email gmail pop3


    【解决方案1】:

    由于Gmail POP3服务器不像普通的POP3服务器那样工作,即使邮件没有被删除,它也会自动隐藏旧邮件,所以我建议你使用IMAP4协议,然后你会阅读所有邮件。

    只需更改: imap.gmail.com 的服务器地址, 服务器端口为 993, ServerProtocol.Pop3 到 ServerProtocol.Imap4

    就像这样:

    private void readMails(){
            MailServer oServer=new MailServer("imap.gmail.com", "something@gmail.com", "noneedtoseethis", ServerProtocol.Imap4);
            MailClient oClient = new MailClient("Client");
            oServer.SSLConnection = true;
            oServer.Port = 993;
            try {
                oClient.Connect(oServer);
                MailInfo[] infos = oClient.GetMailInfos();
                Console.WriteLine(infos.Length);
                for (int i = 0; i < infos.Length; i++){
                    MailInfo info = infos[i];
                    Mail oMail = oClient.GetMail(info);
    
                    Console.WriteLine("From: {0}", oMail.From.ToString());
                    //oClient.Delete(info);
                }
                oClient.Quit();
            } catch (Exception ep) {
                Console.WriteLine(ep.Message);
            }
        }
    

    【讨论】:

    • 快速提问,我即将创建一个系统来监控一些收件箱,你会推荐 EAGetMail 库吗?还是有更好的包?
    • @Jenny 1985 还有其他方法可以使用 SSL 连接到 Imap4 以读取消息吗?尚未使用 Microsoft.Office.Interop.Outlook 为我工作
    猜你喜欢
    • 2017-09-23
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多