C#: Login into email/Click email/Open link?

Status
Not open for further replies.

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
I want to make a bot that logs into someones email, open a certain email, then clicks the link inside the email to confirm their accounts.

Here is the code someone helped me out with. Can you see if its right?

Code:
 private string HTTP_POST(string host, string path, string postdata, bool SetCookies)
        {
            try
            {
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://" + host + path);
                req.Method = "POST";
                req.Host = host;
                req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b6) Gecko/20100101 Firefox/4.0b6";
                req.Accept = "*/*";
                req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] loginDataBytes = encoding.GetBytes(postdata);
                req.ContentLength = loginDataBytes.Length;
                Stream stream = req.GetRequestStream();
                stream.Write(loginDataBytes, 0, loginDataBytes.Length);
                stream.Close();

                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                StreamReader sr = new StreamReader(res.GetResponseStream());
                return sr.ReadToEnd();
            }
            catch (Exception err)
            {
                return "ERR" + err.Message;
            }

        }

              public void Login()
        {
            string html = HTTP_POST("www.***.com", "/cmy/***/login/",
                                "username=" + Account.Name + "&password=" + Account.Password + "&next=", true);
        }

        public string[] GetAllMatches(string _html)
        {
            System.Collections.Generic.List<String> matches =  Regex("<a href=\"/cmy/match/([0-9]*)/\">Details</a>",  _html);
            return matches.ToArray();
        }

private List<string> Regex(string p,string _html)
{
     throw new NotImplementedException();
}

         private string GetSomething(string _html)
        {
            Regex r_token = new Regex("\\[_csrf_token]\" value=\"([0-9A-Za-z]*)\"", RegexOptions.None);
            Match m = r_token.Match(_html);
            if (m.Success)
            {
                return r_token.Match(_html).Groups[1].Value;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Token Error");
                return null;
            } 
        }

    }
 

Chaddith

Member
member
Joined
Jul 31, 2011
Posts
17
Reaction score
2
Points
0
First off, you are going to need more methods then that. Your HTTP Wrappers lack a lot of functionality.
Secondly, you would need to be able to support HTTPS.
Thirdly, you would need to find all the POST data while logging in using HTTP Fox or Live HTTP Headers. You would then probably have to find how they encrypt their data because almost all the sites that use HTTPS encrypt their login details.

You are better off learning POP3 and downloading all the emails then filtering out the one you want.
 
Status
Not open for further replies.