ASP.NET - Import yahoo contacts and inbox in asp.net gridview using C#

Asked By tracker tt
24-Jan-12 12:27 PM
I got gmail contacts into a gridview .What is the code to get yahoo and rediff contacts into my asp.net applications?Similarly what is the code to display my yahoo and rediff inbox  into a table in asp.net application?
  D Company replied to tracker tt
24-Jan-12 12:42 PM
hello friend,

here is the sample code, modify it and compile

using System;
using System.Collections.Specialized;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace Gnilly.Syndication.Mail
{
    public class YahooExtract
    {
      private const string _addressBookUrl = "http://address.yahoo.com/yab/us/Yahoo_ab.csv?loc=us&.rand=1671497644&A=H&Yahoo_ab.csv";
      private const string _authUrl = "https://login.yahoo.com/config/login?";
      private const string _loginPage = "https://login.yahoo.com/config/login";
      private const string _userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";

      public bool Extract( NetworkCredential credential, out MailContactList list )
      {
        bool result = false;

        list = new MailContactList();

        try
        {
          WebClient webClient = new WebClient();
          webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;
          webClient.Encoding = Encoding.UTF8;

          byte[] firstResponse = webClient.DownloadData( _loginPage );
          string firstRes = Encoding.UTF8.GetString( firstResponse );


          NameValueCollection postToLogin = new NameValueCollection();
          Regex regex = new Regex( "type=\"hidden\" name=\"(.*?)\" value=\"(.*?)\"", RegexOptions.IgnoreCase );
          Match match = regex.Match( firstRes );
          while ( match.Success )
          {
            if ( match.Groups[ 0 ].Value.Length > 0 )
            {
              postToLogin.Add( match.Groups[ 1 ].Value, match.Groups[ 2 ].Value );
            }
            match = regex.Match( firstRes, match.Index + match.Length );
          }


          postToLogin.Add( ".save", "Sign In" );
          postToLogin.Add( ".persistent", "y" );

          string login = credential.UserName.Split( '@' )[ 0 ];
          postToLogin.Add( "login", login );
          postToLogin.Add( "passwd", credential.Password );

          webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;
          webClient.Headers[ HttpRequestHeader.Referer ] = _loginPage;
          webClient.Encoding = Encoding.UTF8;
          webClient.Headers[ HttpRequestHeader.Cookie ] = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];

          webClient.UploadValues( _authUrl, postToLogin );
          string cookie = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];

          if ( string.IsNullOrEmpty( cookie ) )
          {
            return false;
          }

          string newCookie = string.Empty;
          string[] tmp1 = cookie.Split( ',' );
          foreach ( string var in tmp1 )
          {
            string[] tmp2 = var.Split( ';' );
            newCookie = String.IsNullOrEmpty( newCookie ) ? tmp2[ 0 ] : newCookie + ";" + tmp2[ 0 ];
          }

          // set login cookie
          webClient.Headers[ HttpRequestHeader.Cookie ] = newCookie;
          byte[] thirdResponse = webClient.DownloadData( _addressBookUrl );
          string thirdRes = Encoding.UTF8.GetString( thirdResponse );

          string crumb = string.Empty;
          Regex regexCrumb = new Regex( "type=\"hidden\" name=\"\\.crumb\" id=\"crumb1\" value=\"(.*?)\"", RegexOptions.IgnoreCase );
          match = regexCrumb.Match( thirdRes );
          if ( match.Success && match.Groups[ 0 ].Value.Length > 0 )
          {
            crumb = match.Groups[ 1 ].Value;
          }


          NameValueCollection postDataAB = new NameValueCollection();
          postDataAB.Add( ".crumb", crumb );
          postDataAB.Add( "vcp", "import_export" );
          postDataAB.Add( "submit[action_export_yahoo]", "Export Now" );

          webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;
          webClient.Headers[ HttpRequestHeader.Referer ] = _addressBookUrl;

          byte[] FourResponse = webClient.UploadValues( _addressBookUrl, postDataAB );
          string csvData = Encoding.UTF8.GetString( FourResponse );

          string[] lines = csvData.Split( '\n' );
          foreach ( string line in lines )
          {
            string[] items = line.Split( ',' );
            if ( items.Length < 5 )
            {
              continue;
            }
            string email = items[ 4 ];
            string name = items[ 3 ];
            if ( !string.IsNullOrEmpty( email ) && !string.IsNullOrEmpty( name ) )
            {
              email = email.Trim( '\"' );
              name = name.Trim( '\"' );
              if ( !email.Equals( "Email" ) && !name.Equals( "Nickname" ) )
              {
                MailContact mailContact = new MailContact();
                mailContact.Name = name;
                mailContact.Email = email;
                list.Add( mailContact );
              }
            }
          }

          result = true;
        }
        catch
        {
        }
        return result;
      }
    }
}





Hope this will help you
Regards
D
  kalpana aparnathi replied to tracker tt
24-Jan-12 01:04 PM
hi,

For contacts:


http://www.zoomasp.net/Yahoo_Contact_Importer_csharp.aspx%20

%20http://www.ideabubbling.com/TestDrive.aspx

 http://gnillydev.blogspot.com/2007/10/yahoo-contact-import-class-in-c.html

 http://www.codeproject.com/KB/cs/gmailagent.aspx
  Riley K replied to tracker tt
24-Jan-12 08:42 PM


Whenever you want to read contacts from Yahoo, gmail they provide with an API which is very simple to use

http://developer.yahoo.com/addressbook/ 
http://developer.yahoo.com/dotnet/howto-rest_cs.html 
http://developer.yahoo.com/dotnet/howto-rest_cs.html 


Regards
  Suchit shah replied to tracker tt
25-Jan-12 05:15 AM
Yahoo! offers 3 ways to connect with their services, the first is OpenID to authenticate users, the second one is OAuth to control access to protected data and the third one is OpenID-OAuth Hybrid Protocol, which combines OpenID authentication with OAuth authorization in a single interface. I found OAuth is most convincing and will stick to it for this article. If you want to know more about other 2 authentication models, I suggest you http://developer.yahoo.com/auth/. Before jumping to the implementation with OAuth model, let's refresh our mind with a quick review of basic OAuth mechanism.

http://www.codeproject.com/Articles/91646/Implementing-Yahoo-Contact-Reader-Using-ASP-NET

Yahoo

1. Register your application to get consumer key and consumer secret
http://developer.yahoo.com/bbauth/appreg.html
Don't forgot to change prermision to read Contacts
2. Download and extract DotNetOpenAuth-3.4.7.1112 from http://www.dotnetopenauth.net/
3. Add DotNetOpenAuth.dll to project references
4. Download file OAuthBase.cs from http://oauth.googlecode.com/svn/code/csharp/ and add to project

Create New Account
help
function () { $( '#<% = hdName.ClientID%> ' ).val( "YOUR TEXT" ); }); < / script > < / head > < body > < form id = "form1" runat = "server" > < div > < asp:Label ID = "lblName" runat = "server" Text = "Label" > < / asp:Label > < asp:HiddenField ID = "hdName" runat = "server" / > < asp:Button ID = "Button1" runat = "server" Text = "Button" OnClick = "Button1_Click" / > < / div > < / form > < / body > < / html > Check for width: 191px"> <tr> <td style = "height: 23px"> Suriyan < / td> <td style = "width: 81px; height: 23px;"> <asp:DropDownList ID = "Dropsuriyan" runat = "server" onchange = "changeText('lblR', this, 'Suriyan')" Width = "88px"> <asp:ListItem> 0< / asp:ListItem> <asp:ListItem> 1< / asp:ListItem> <asp:ListItem> 2< / asp:ListItem> <asp:ListItem> 3< / asp:ListItem> <asp
Help me. . . . . . hi all, i just want to say that actually i am new to asp.net 2.0 i have a work over my head and really m not knowing how strong > < / td > < / tr > < tr > < td align = "center" style = "height: 30px; width: 384px; background-color: ActiveBorder" > < asp : Label ID = "lblUserID" runat = "server" Text = "UserID :" ForeColor = "#003300" > < / asp : Label > < / td > < td align = "center" style = "height: 28px; width: 312px; background-color: ActiveBorder" > < asp : TextBox ID = "txtUserID" runat = "server" style = "z-index: 100; left: 274px; position: absolute; top: 53px asp : TextBox > < asp : RequiredFieldValidator ID = "RequiredFieldValidator1" runat = "server" ControlToValidate = "txtUserID" ErrorMessage = "*" Style = "z-index: 102; left: 441px; position: absolute; top: 54px"> < / asp : RequiredFieldValidator > < / td > < / tr > < tr > < td align = "center" style = "height: 30px; width: 384px ; background-color: ActiveBorder
to bind data to the radiobutton frm table. . ? plz help me hi, aspx page code < asp:RadioButtonList id = "RadioButtonList1" runat = "server" > < / asp:RadioButtonList > < asp:Button ID = "btnTest" Runat = "server" Text = "Submit" > < / asp:Button > code-behind code. protected System.Web.UI.WebControls.Button btnTest; protected System.Web.UI server" > < title > Linear Wizard < / title > < / head > < body > < form id = "form1" runat = "server" > < div align = center > < asp:Wizard ID = "Wizard1" runat = "server" BackColor = "#FFFBD6" BorderColor = "#FFDFAD" onfinishbuttonclick = "scorefunction" Height = "160px" Width = "480px SideBarButtonStyle-Font-Size = "Small" SideBarButtonStyle-Font-Bold = "true" SideBarStyle-BackColor = "AliceBlue" SideBarStyle-BorderColor = "Red" > < WizardSteps > < asp:WizardStep runat = "server" id = step1 StepType = "Start" > 1.When did India got independence? < asp:RadioButtonList ID = "RBL1" runat = "server" > < asp:ListItem Value = "a" > 1947 < / asp:ListItem > < asp:ListItem Value = "b" > 1847 < / asp:ListItem > < asp:ListItem
I want to export contact address from my email id by programming in Asp.net , C#.net. Please Guide ! As per my Web Application , Requirement. I have to export my contact address from my email id. Like if I have email id in yahoo , and i give my email id and it's password. Then by programming in asp.net and C#.net , I will export my contact address from this email id. using System; using System.Collections.Specialized; using System.Net; using System.Text; using System.Text.RegularExpressions; namespace Gnilly.Syndication.Mail { public class YahooExtract { private