c#使用pop3服务器进行邮箱验证

4 篇文章 0 订阅

环境

开发环境:.net4.0+vs2013
操作系统:win8.1

内容

由于项目需要,拟开发一个模块进行邮箱验证操作,最终采取使用pop3服务器进行邮箱登陆并且获取内容

编码

  /// <summary>
        /// 点击链接
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static bool Click2(Info info)
        {
            //GC.Collect();
            using (POP3_Client pop3 = new POP3_Client())
            {
                //选择pop3服务器的地址,这里只提供了189和139邮箱 有需要的可以自己去加
                pop3.Logger = new Logger();
                string _url = "";
                if (info.Email.Contains("@189.cn"))
                {
                    _url = "pop.189.cn";
                }
                else if (info.Email.Contains("@"))
                {
                    _url = "pop.139.com";
                }
                else
                {
                    return false;
                }

                //连接pop3服务器
                pop3.Connect(_url, 110, false);

                //尝试登陆
                try
                {
                    pop3.Authenticate(info.Email, info.PassWord, true);

                }
                catch (Exception ex)
                {
                    return false;
                }

                //逆序遍历,可以获得最新的邮件内容
                for (int i = pop3.Messages.Count - 1; i >= 0; i--)
                {
                    POP3_ClientMessage message = pop3.Messages[i];
                    try
                    {
                        Mail_Message mime = Mail_Message.ParseFromByte(message.MessageToByte());
                        string text = mime.BodyHtmlText;
                        //根据关键词判断是否为自己需要读取的邮件
                        if (text.Contains("Confirm your signature by clicking here."))
                        {
                            //正则获得需要点击的链接并且点击
                            string url = MyTool.MyRegex.StringRegex(text, @"<p><strong><a href=""([\s\S]*?)""");
                            url = url.Replace("amp;", "");
                            string html = HttpAdd.OnlyGetHtml(url);//点击链接
                            if (html.Contains("You've successfully signed the petition below. Your signature has been verified and counted."))
                            {

                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }

            return false;
        }

第三方类库

实现此模块需要基于LumiSoft.Net该类库
百度网盘下载链接:
http://pan.baidu.com/s/1kU5BXrh 密码:evtv

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值