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

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

c# 利用MailKit.IMap 收取163邮件的更多相关文章

  1. c# 利用IMap 收取163邮件

    最近我要做一个爬虫.这个爬虫需要如下几个步骤: 1 填写注册内容(需要邮箱注册) 2 过拖拽验证码(geetest) 3 注册成功会给邮箱发一封确认邮箱 4 点击确认邮箱中的链接 完成注册 我这里就采 ...

  2. centos 6.4 getmail 收取163 邮件

    #CentOS 6.6 64bit 默认yum 源没有getmail rpm包#首先安装EPEL yum 源EPEL(Extra Packages for Enterprise Linux):http ...

  3. Android pop3与imap方式接收邮件(javamail)

    需要下载3个jar包:mail.jar/    activation.jar/    additionnal.jar 1.pop3 /** * 以pop3方式读取邮件,此方法不能读取邮件是否为已读,已 ...

  4. foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误

    foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误,收件.发件服务器配置需要用imap.ym.163.com,smtp.ym.163.com三级域名,帐 ...

  5. MailKit和MimeKit 收发邮件

    新建项目,引用MailKit和MimeKit NuGet包 using CommonTool.MailKit; using System; using System.Collections.Gener ...

  6. php使用CI发送qq和163邮件

    1.需求 发送邮件 2.介绍 使用CI框架的email类库发送邮件,这里演示QQ和163 3.163使用教程 a.先去163邮件开启smtp邮件. b.在CI的控制器里写下面的代码 $this-> ...

  7. linux mail利用外部邮箱地址发邮件

    mail命令发送邮件需要sendmail或postfix服务 三种常用格式发信 mail -s "标题" xxx@xxx.xxx #第一种方法,你可以把当前shell当成编辑器来用 ...

  8. 解决.NET Core中MailKit无法使用阿里云邮件推送服务的问题

    在博问中(.net core怎么实现邮件发送)知道了MailKit无法使用阿里云邮件推送服务发送邮件的问题,自已实测也遇到同样的问题,而用自己搭建的邮件服务器没这个问题. 于是,向阿里云提交了工单.. ...

  9. phpmailer使用163邮件发送邮件例子

    注意:如果你的服务器安装了卖咖啡并且开户病毒最大防护功能我们需要关闭一个邮件防护哦,否则你的邮件发不出去给被这款杀毒给拦截哦. 1. 使用gmail发送的脚本 代码如下 复制代码 include(&q ...

随机推荐

  1. 有关 PHP 的 10 道问题

    1.简述面向对象的三大特性 答:封装 --  继承  --  多态 封装的目的:为了让类更安全 继承的概念:子类可以继承父类的一切 多态的概念:当父类引用指向子类实例,由于子类里面对父类的方法进行了重 ...

  2. Codeforces 698A - Vacations - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/698/A 题意: 有 $n$ 天假期,每天有四种情况:0.体育馆不开门,没有比赛:1.体育馆不开门,有比赛 ...

  3. JS弹出对话框的三种方式

    JS弹出对话框的三种方式 我们用到了alert()方法.prompt()方法.prompt()方法,都是在网页有一个弹出框,那么就让我们探究一下他们之间的区别: 一.第一种:alert()方法 < ...

  4. zabbix客户端自动注册

    1. 概述 上一篇内容<zabbix自动发现配置>,大概内容是zabbix server去扫描一个网段,把在线的主机添加到Host列表中.我们本篇内容与上篇相反,这次是Active age ...

  5. linux命令瞎记录find xargs

    1.创建多个文件 touch test{0..100}.txt 2.重定向 “>>” 追加重定向,追加内容,到文件的尾部 “>” 重定向,清除原文件里面所有内容,然后把内容追加到文件 ...

  6. day2_Jmeter压测

    1.线程组各项设置的意思 2.压测结果查看各指标意思 备注:tps:每秒钟系统能够处理的交易或事务的数量.它是衡量系统处理能力的重要指标.tps越高说明服务器处理能力越好. 3.在一台电脑上做一个简单 ...

  7. Android SDK 环境变量

    系统变量 PATH中加入 C:\Program Files (x86)\Android\android-sdk\platform-tools 和 C:\Program Files (x86)\Andr ...

  8. TensorFlow环境

    vps cenots7自带的python2.7各种毛病,浪费了不少时间,装了pyhton3一下就搞定了 mac上有些依赖库需要sudo安装 vps上是基于Anaconda搭建的,感谢极客学院的教程ht ...

  9. 集齐所有机制的按键控制LED驱动

    内核版本:linux2.6.22.6 硬件平台:JZ2440 驱动源码 final_key.c : #include <linux/module.h> #include <linux ...

  10. linux根文件系统制作,busybox启动流程分析

    分析 busybox-1.1.6 启动流程,并 制作一个小的根文件系统 源码百度云链接:https://pan.baidu.com/s/1tJhwctqj4VB4IpuKCA9m1g 提取码 :l10 ...