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

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

http://www.mimekit.net/docs/html/M_MailKit_Net_Imap_ImapClient_Identify.htm

public static void Capabilities ()
{
using (var client = new ImapClient ()) {
client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect); var mechanisms = string.Join (", ", client.AuthenticationMechanisms);
Console.WriteLine ("The IMAP server supports the following SASL authentication mechanisms: {0}", mechanisms); client.Authenticate ("username", "password"); if (client.Capabilities.HasFlag (ImapCapabilities.Id)) {
var clientImplementation = new ImapImplementation { Name = "MailKit", Version = "1.0" };
var serverImplementation = client.Identify (clientImplementation); Console.WriteLine ("Server implementation details:");
foreach (var property in serverImplementation.Properties)
Console.WriteLine (" {0} = {1}", property.Key, property.Value);
} if (client.Capabilities.HasFlag (ImapCapabilities.Acl)) {
Console.WriteLine ("The IMAP server supports Access Control Lists."); Console.WriteLine ("The IMAP server supports the following access rights: {0}", client.Rights); Console.WriteLine ("The Inbox has the following access controls:");
var acl = client.Inbox.GetAccessControlList ();
foreach (var ac in acl)
Console.WriteLine (" {0} = {1}", ac.Name, ac.Rights); var myRights = client.Inbox.GetMyAccessRights ();
Console.WriteLine ("Your current rights for the Inbox folder are: {0}", myRights);
} if (client.Capabilities.HasFlag (ImapCapabilities.Quota)) {
Console.WriteLine ("The IMAP server supports quotas."); Console.WriteLine ("The current quota for the Inbox is:");
var quota = client.Inbox.GetQuota (); if (quota.StorageLimit.HasValue && quota.StorageLimit.Value)
Console.WriteLine (" Limited by storage space. Using {0} out of {1} bytes.", quota.CurrentStorageSize.Value, quota.StorageLimit.Value); if (quota.MessageLimit.HasValue && quota.MessageLimit.Value)
Console.WriteLine (" Limited by the number of messages. Using {0} out of {1} bytes.", quota.CurrentMessageCount.Value, quota.MessageLimit.Value); Console.WriteLine ("The quota root is: {0}", quota.QuotaRoot);
} if (client.Capabilities.HasFlag (ImapCapabilities.Thread)) {
if (client.ThreadingAlgorithms.Contains (ThreadingAlgorithm.OrderedSubject))
Console.WriteLine ("The IMAP server supports threading by subject.");
if (client.ThreadingAlgorithms.Contains (ThreadingAlgorithm.References))
Console.WriteLine ("The IMAP server supports threading by references.");
} client.Disconnect (true);
}
}

最新文章

  1. Html5 冒泡排序演示
  2. ROS 5.x自动定时备份并发送到邮箱(实用)
  3. Hadoop - Unable to load native-hadoop library for your platform
  4. 实例存储支持的AMI创建步骤
  5. css通用小笔记02——浮动、清除(三个例子)
  6. Feature hashing相关 - 2
  7. cocos基础教程(4)基础概念介绍
  8. python 深入理解 赋值、引用、拷贝、作用域
  9. Hibernate征途(七)之复合主键映射和集合映射
  10. c语言与c++基础知识
  11. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
  12. 【转】你应该知道的十个VirtualBox技巧与高级特性
  13. Django之CSRF 跨站请求伪造
  14. js 16进制字符串互转
  15. 嵌入jetty到Java代码
  16. .NET MVC学习笔记(一)
  17. Centos6.6升级python版本
  18. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1
  19. ELK的高级篇(测试记录各种日志)
  20. SCU 4439 Vertex Cover(二分图最小覆盖点)题解

热门文章

  1. Docker学习之——Node.js+MongoDB+Nginx环境搭建(一)
  2. weblogic启动项目,设置内容、设置的数据源链接不生效
  3. vue setTimeout 注销
  4. nowcoder 211E - 位运算?位运算! - [二进制线段树][与或线段树]
  5. [No0000178]改善C#程序的建议1:非用ICloneable不可的理由
  6. hbase与hive集成:hive读取hbase中数据
  7. 自动化运维工具-pssh工具安装配置及简单使用讲解
  8. 使用shell删除目录下几天前生成文件方法
  9. gitignore 不起作用的解决办法
  10. C# decimal指定精度