c# 利用MailKit.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
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邮件的更多相关文章
- c# 利用IMap 收取163邮件
最近我要做一个爬虫.这个爬虫需要如下几个步骤: 1 填写注册内容(需要邮箱注册) 2 过拖拽验证码(geetest) 3 注册成功会给邮箱发一封确认邮箱 4 点击确认邮箱中的链接 完成注册 我这里就采 ...
- centos 6.4 getmail 收取163 邮件
#CentOS 6.6 64bit 默认yum 源没有getmail rpm包#首先安装EPEL yum 源EPEL(Extra Packages for Enterprise Linux):http ...
- Android pop3与imap方式接收邮件(javamail)
需要下载3个jar包:mail.jar/ activation.jar/ additionnal.jar 1.pop3 /** * 以pop3方式读取邮件,此方法不能读取邮件是否为已读,已 ...
- foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误
foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误,收件.发件服务器配置需要用imap.ym.163.com,smtp.ym.163.com三级域名,帐 ...
- MailKit和MimeKit 收发邮件
新建项目,引用MailKit和MimeKit NuGet包 using CommonTool.MailKit; using System; using System.Collections.Gener ...
- php使用CI发送qq和163邮件
1.需求 发送邮件 2.介绍 使用CI框架的email类库发送邮件,这里演示QQ和163 3.163使用教程 a.先去163邮件开启smtp邮件. b.在CI的控制器里写下面的代码 $this-> ...
- linux mail利用外部邮箱地址发邮件
mail命令发送邮件需要sendmail或postfix服务 三种常用格式发信 mail -s "标题" xxx@xxx.xxx #第一种方法,你可以把当前shell当成编辑器来用 ...
- 解决.NET Core中MailKit无法使用阿里云邮件推送服务的问题
在博问中(.net core怎么实现邮件发送)知道了MailKit无法使用阿里云邮件推送服务发送邮件的问题,自已实测也遇到同样的问题,而用自己搭建的邮件服务器没这个问题. 于是,向阿里云提交了工单.. ...
- phpmailer使用163邮件发送邮件例子
注意:如果你的服务器安装了卖咖啡并且开户病毒最大防护功能我们需要关闭一个邮件防护哦,否则你的邮件发不出去给被这款杀毒给拦截哦. 1. 使用gmail发送的脚本 代码如下 复制代码 include(&q ...
随机推荐
- 【Linux】解决Android Stadio报错:error in opening zip file
报错: Failed to complete Gradle Execution Cause: error in opening zip file. 原因: 安装gradle失败引起的,往往是上网需要验 ...
- CentOS和Redhat单用户模式
当系统无法启动时,可能是/etc/fstab挂载错误导致这时候可以进入单用户模式修改配置文件后重启 重启系统出现以下界面按e 选择第二栏按e健 在后面输入1回车回到上一个页面按b健启动 进入单用户模式 ...
- [No0000131]WCF压缩传输方案整理
1.WCF进阶:将编码后的字节流压缩传输 2.通过WCF扩展实现消息压缩 3.WCF 消息压缩性能问题及解决方法
- [No0000D6]端口-进程查询.bat
@echo off color a Title XP端口-进程查询 setlocal enabledelayedexpansion echo ╔- -╗ echo 本机开放的端口及使用该端口的进程 e ...
- 【每日一题】 UVA - 1587 Box 二维有点偏序的感觉
一开始用set存xjb分类讨论,然后wa, 然后简化了一点,改用vector,然wa 最后又发现没有初始化,然wa wa了一个半小时 最后看了题解orz 然后找了一组样例把自己的代码改对了 /* 1 ...
- 通用网关接口 ruby perl web页面 文本处理 脚本语言
小结: 1.只要可以对标准输入输出进行操作,那么无论任何语言都可以编写CGI程序. <代码的未来> 在Ruby诞生的1993年,互联网还没有现在这样普及,因此Ruby也不是一开始就面向We ...
- [others]tinycore/microcore
https://zh.wikipedia.org/wiki/Tiny_Core_Linux https://github.com/zeit/micro
- python发送邮件 大全汇总
https://blog.csdn.net/bmxwm/article/details/79007871 参考菜鸟教程发送只有文字的邮件 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
- kubernetes的Controller Manager
1. Controller Manager简介 Controller Manager作为集群内部的管理控制中心,负责集群内的Node.Pod副本.服务端点(Endpoint).命名空间(Namespa ...
- 【python-opencv】30-角点检测
[微语]世上有很多不可能,不过不要在你未尽全力之前下结论 特征检测:找到图像特征的技术 特征描述:描述图像特征 Harris角点检测(Corner Detection) 参考: https://doc ...