俄罗斯邮箱Mail.ru的登录及获取邮箱内容(c#实现)

本文详细介绍了如何使用C#语言登录俄罗斯的Mail.ru邮箱,并获取邮箱内容。步骤包括获取登录页面的cookie,验证账号密码,获取登录token,以及访问邮箱列表和内容。请注意,此过程涉及禁止重定向和网络数据处理。
摘要由CSDN通过智能技术生成

登录网址: https://account.mail.ru/login

***********************注:本文仅作学习交流,如有侵权,请私信删除。

1. 访问登录页面: 获取cookie值 

    private bool GetIndex()
    {
            string url = "https://account.mail.ru/login";
            HttpClient client = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
            request.Headers.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
            request.Headers.Add("accept-encoding", "gzip, deflate, br");
            request.Headers.Add("accept-language", "zh-CN,zh;q=0.9");
            request.Headers.Add("user-agent", UserAgent);
            HttpResponseMessage response = client.SendAsync(request).Result;

            if (!response.IsSuccessStatusCode)
            {
                Msg = "网络错误";
                return false;
            }
            List<string> setCookie = response.Headers.GetValues("set-cookie").ToList();
            cookies = ToolData.getCookies(setCookie);
            actToken = ToolData.getCookieValue(setCookie, "act");
            return true;
        }

2. 输入账号: 验证账号是否存在

        private bool InputAccount()
        {
            string url = "https://auth.mail.ru/api/v1/pushauth/info";
            HttpClient client = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
            request.Headers.Add("accept", "*/*");
            request.Headers.Add("accept-encoding", "gzip, deflate, br");
            request.Headers.Add("accept-language", "zh-CN,zh;q=0.9");
            request.Headers.Add("Host", "auth.mail.ru");
            request.Headers.Add("Origin", "https://account.mail.ru");
            request.Headers.Add("Referer", "https://account.mail.ru/login");
            request.Headers.Add("cookie", cookies);
            request.Headers.Add("user-agent", UserAgent);

            string data = $"email={HttpUtility.UrlEncode(email)}&utm=&htmlencode=false&login={HttpUtility.UrlEncode(email)}";
            request.Content = new StringContent(data);
            request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
            request.Content.Headers.ContentLength = data.Length;

            HttpResponseMessage response = client.SendAsync(request).Result;
            if (response.IsSuccessStatusCode)
            {
                string content = response.Content.ReadAsStringAsync().Result;
                JObject json = JObject.Parse(content);
                if (Convert.ToBoolean(json.SelectToken("body.exists")))
                {
                    return InputPwd();
                }
            }

            Msg = "该账号不存在";
            return false;
        }

3. 输入账号和密码: 确认账号和密码是否正确

        private
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值