获取 Email 的通讯录邮箱

最近接到了一项任务,就是要做个类似开心网 SNS 网站邀请好友的功能。

查了一些资料以后,发现更多的是用 PHP 或 java 的例子。 .Net C# 的很少.

参考了他们的例子。自己写了一个. 主要是应用 .Net 的 WebRequest ,HttpWebRequest ,WebResponse , HttpWebResponse 几个类.

个人心得: 登录邮箱各不同,分析路径要耐心。 Http 的间断链接,需要把 HttpHeader 获得后再发回去. 压缩包中有个例子(含源码)。

有兴趣的继续研究的朋友可以Mail我 Dev.guyan # Gmail.com 非诚勿扰

 

PS...    >_<  CSDN 的资源上传总说验证码不对....


贴一段主要的代码

private string GetRequestHtml(string URL, Encoding EnCodeing,ReqMethod RMethod)  
       {  
           string html = string.Empty;  
           try 
           {  
               req = (HttpWebRequest)WebRequest.Create(URL);  
               req.AllowAutoRedirect = true;  
               req.CookieContainer = cookieCon;  
               req.Credentials = CredentialCache.DefaultCredentials;  
               req.Method = RMethod.ToString();  
               req.ContentType = "application/x-www-form-urlencoded";  
               req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59  from: http://bsalsa.com/ ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)";  
 
               res = (HttpWebResponse)req.GetResponse();  
 
               if (cookieheader.Equals(string.Empty))  
               {  
                   cookieheader = req.CookieContainer.GetCookieHeader(new Uri(URL));  
               }  
               else 
               {  
                   req.CookieContainer.SetCookies(new Uri(URL), cookieheader);  
               }  
 
               html= new StreamReader(res.GetResponseStream(), EnCodeing).ReadToEnd();  
           }  
           catch (Exception ex)  
           {  
               html = ex.Message;  
           }  
           return html;  
       } 
 private string GetRequestHtml(string URL, Encoding EnCodeing,ReqMethod RMethod)
        {
            string html = string.Empty;
            try
            {
                req = (HttpWebRequest)WebRequest.Create(URL);
                req.AllowAutoRedirect = true;
                req.CookieContainer = cookieCon;
                req.Credentials = CredentialCache.DefaultCredentials;
                req.Method = RMethod.ToString();
                req.ContentType = "application/x-www-form-urlencoded";
                req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59  from: http://bsalsa.com/ ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)";

                res = (HttpWebResponse)req.GetResponse();

                if (cookieheader.Equals(string.Empty))
                {
                    cookieheader = req.CookieContainer.GetCookieHeader(new Uri(URL));
                }
                else
                {
                    req.CookieContainer.SetCookies(new Uri(URL), cookieheader);
                }

                html= new StreamReader(res.GetResponseStream(), EnCodeing).ReadToEnd();
            }
            catch (Exception ex)
            {
                html = ex.Message;
            }
            return html;
        }

源代码吗下载: http://www.rssink.com/Temp/GetEmailContacts.rar

 

转自:http://blog.csdn.net/skylen/archive/2009/03/27/4028906.aspx

你可能感兴趣的:(email)