Asp.net captures the sina email contact implementation code

Source: Internet
Author: User
The code is as follows: Copy code

Using System;
Using System. Net;
Using System. IO;
Using System. Text;
Using System. Collections. Specialized;
Using System. Text. RegularExpressions;
/*
* AddressSina
* Sina free email contact (sina.com/sina.cn)
 *
* Change? Performance? S
* Ver 1.00.00 @ [20100721] Xingyuan Mengyu Xin?
* Ver 2.00.00 @ [20110807] Xingyuan Mengyu upgrade
*/

Namespace GetEmailAddress
{
Internal class AddressSina: AddressBase
 {
Private string refererurl; // store the request address
// Send an email request to log on
Public override GetAddressStatus Login ()
  {
Try
   {
// 20110807 new rule
// Get the Sina free email type ending with com or cn.
String url = "";
String postdata = "";
String mailType = this. Credential. UserName. Substring (this. Credential. UserName. IndexOf ("@"));
Switch (mailType)
                {
Case "@ sina.com ":
// 20110807 amendment
Url = "http://mail.sina.com.cn/cgi-bin/login.cgi ";
// Request to log on to obtain postdata data
Postdata = "logintype = uid & u =" + this. credential. userName. substring (0, this. credential. userName. indexOf ("@") + "& psw =" + this. credential. password + "& product = mail & % B5 % C7 % C2 % BC = % B5 % C7 + % C2 % BC ";
Break;
Case "@ sina.cn ":
// 20110807 new rule
Url = "http://mail.sina.com.cn/cgi-bin/cnlogin.php ";
// Request to log on to obtain postdata data
Postdata = "domain = sina.cn & logintype = uid & u =" + this. credential. userName. substring (0, this. credential. userName. indexOf ("@") + "& psw =" + this. credential. password + "& x = 40 & y = 19 ";
Break;
Default: break;
                }
// Postdata data length
Byte [] buf = System. Text. Encoding. UTF8.GetBytes (postdata );
HttpWebResponse loginresponse = SendRequest ("POST", url, "http://m0.mail.sina.com.cn/classic/index.php", buf );
Refererurl = loginresponse. ResponseUri. ToString ();
// ResponseUri address changed. Login successful
If (refererurl = url)
Return GetAddressStatus. UidOrPwdError;
   }
Catch
   {
Return GetAddressStatus. NetError;
   }
Return GetAddressStatus. Success;
  }
/// <Summary>
/// Return the array of mailboxes.
/// </Summary>
/// <Param name = "page"> obtain the Mail information in array format. </Param>
/// <Param name = "encoding"> the encoding format prevents garbled characters. </Param>
/// <Returns> returns the array of mailbox data. </Returns>
Public override bool GetAddressPage (out string page, Encoding encoding)
  {
Page = null;
// Address book url
String host = refererurl. Substring (7 );
Host = host. Substring (0, host. IndexOf ("/"));
String addressurl = "http: //" + host + "/classic/addr_member.php ";
// Act = list & gid = 0 & sort_item = letter & sort_type = desc
// Gid = 0 is not added here because the whole page data is captured by adding 0. Remove and only capture data in the contacts array
String postdata = "act = list & sort_item = letter & sort_type = desc ";
// Request parameters
// Act = list & sort_item = letter & sort_type = desc
Byte [] buf = System. Text. Encoding. UTF8.GetBytes (postdata );
Try
   {
HttpWebResponse sinaAddressResponse = SendRequest ("POST", addressurl, refererurl, buf );
Page = GetPageByResponse (sinaAddressResponse, encoding );
// Cancel
String logouturl = "http: //" + host + "/classic/logout. php? From = mail ";
HttpWebResponse sinalogoutResponse = SendRequest ("GET", logouturl );
   }
Catch
   {
Return false;
   }
Return true;
  }
 }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.