zoukankan      html  css  js  c++  java
  • c# 利用IMap 收取163邮件

    最近我要做一个爬虫。这个爬虫需要如下几个步骤:

    1 填写注册内容(需要邮箱注册)

    2 过拖拽验证码(geetest)

    3 注册成功会给邮箱发一封确认邮箱

    4 点击确认邮箱中的链接 完成注册

    我这里就采用163邮箱注册。

    邮箱协议有 pop3 和 imap 和 smtp

    我试了pop3  不能够筛选邮件 例如筛选未读 和 发件人这2个条件 所以放弃用pop3

    imap协议是支持的。

    我就找了一个开源的第三方lib:S22.Imap

    用法很简单:

    public void Test163()
            {
                var imapServer = "imap.163.com";
                var port = 993;
                using (ImapClient client = new ImapClient(imapServer, port, "xxxx@163.com", "pwd", AuthMethod.Login, true))
                {
                    // Returns a collection of identifiers of all mails matching the specified search criteria.
                    IEnumerable<uint> uids = client.Search(SearchCondition.Unseen());
                    // Download mail messages from the default mailbox.
                    IEnumerable<MailMessage> messages = client.GetMessages(uids,FetchOptions.HtmlOnly);
    
                    Console.WriteLine("We are connected!");
                }
    
            }

    发现 在login的时候 报错了:

    提示“NO Select Unsafe Login. Please contact kefu@188.com for help”。

    163邮箱也会收到一个告警邮件

     

    经过查证 发现得需要在发送 login 命令之前 得先发送 id 命令

    至于为什么要这么做 我的理解是得先伪装成普通的客户端吧(有理解错误请指出谢谢)

    我fork了一份SS2.imap的代码 打算兼容163的这个特殊情况改掉源码

     

    然后走Login方法就不会报错了

    Github地址:https://github.com/yuzd/S22.Imap

  • 相关阅读:
    Windows API—CreateEvent—创建事件
    C++的注册和回调
    Python内置模块-logging
    使用 C++ 处理 JSON 数据交换格式
    Python生成器
    5.Spring-Boot缓存数据之Redis
    6.Spring-Boot项目发布到独立的tomcat中
    7.Spring-Boot自定义Banner
    8.Spring-Boot之SpringJdbcTemplate整合Freemarker
    9.Spring-Boot之Mybatis-LogBack-Freemarker
  • 原文地址:https://www.cnblogs.com/yudongdong/p/8465551.html
Copyright © 2011-2022 走看看