<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>IMport Gmail Contacts</title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> UserName</td> <td> <asp:TextBox ID="txtgmailusername" runat="server"></asp:TextBox> </td> </tr> <tr> <td> Password</td> <td> <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </td> </tr> </table> </div> <div> <asp:GridView ID="gvmails" runat="server"></asp:GridView> </div> </form> </body> </html> |
using Google.GData.Contacts; using Google.GData.Client; using Google.GData.Extensions; using Google.Contacts; |
public static DataSet GetGmailContacts(string App_Name, string Uname, string UPassword) { DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataColumn C2 = new DataColumn(); C2.DataType = Type.GetType("System.String"); C2.ColumnName = "EmailID"; dt.Columns.Add(C2); RequestSettings rs = new RequestSettings(App_Name, Uname, UPassword); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed<Contact> f = cr.GetContacts(); foreach (Contact t in f.Entries) { foreach (EMail email in t.Emails) { DataRow dr1 = dt.NewRow(); dr1["EmailID"] = email.Address.ToString(); dt.Rows.Add(dr1); } } ds.Tables.Add(dt); return ds; } protected void Button1_Click(object sender, EventArgs e) { DataSet ds = GetGmailContacts("MyNetwork Web Application!", txtgmailusername.Text, txtpassword.Text); gvmails.DataSource = ds; gvmails.DataBind(); } |
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
38 comments :
But i am unable to call references for the dll(s) in class file.
However i have successfully did this in VS 4.0 but the same i can't do in VS 3.5.
Please suggest !
Hi Mantu
Please check the attached sample that is working in VS 3.5
Can u also post code for import contacts from Yahoo & Hotmail.
superb........
Please post code for import contacts from Yahoo & Facebook
its really superb suresh.thank u
i need AOL Contact import API Code
Can u please post the code for retrieving gmail contact profile pic.I have tried the codes in developer's guide but not able to get the pic.
It works like a charm. Keep up the good work! Thanks Suresh!
How to Change PassWord Character from .... to ****.
nice........
Please post code for import contacts from Yahoo & Facebook
hi,
that code was realy nice but there is some problem with that,
no one supposed that secure to enter her/his gmail ID.people used to opening a new page in Gmail domain to enter their IDs there.
Thnaks Buddy its Work Fine for me for gmail..thank you..agan
i need it for for hotmail and yahoo can you can you it it for me...
Very good post suresh. Can you tell me how you have code this demo part.
I have learnt many things from this site and this type of content is not available on other site.
Your articles are really Mind blowing...They help me great every times.I have also followed your Facebook Login. Your articles really fullfill my 98% requirements.
Thanks for posting your valuable resources..!!
please help me. how can i get application name?
Hi Bro
I did this fine.But i want to add s.no to this gridview as a column SNo. k it will be appeared but in the jump format like only even no's or odd no's
i'm using
==============================
DataColumn C1 = new DataColumn("SNo", typeof(int));
C1.ColumnName = "SNo";
dt.Columns.Add(C1);
C1.AutoIncrement = true;
C1.AutoIncrementSeed = 1;
C1.AutoIncrementStep = 1;
======================
pls send me how to add sno to the above grdvw.
Thanks in advance bro
Great job............very good artical
very gr8 job suresh..i really like it
very gr8 job suresh..i really like it
hi Suresh,
I got error that is Google.GData.Client.InvalidCredentialsException: Invalid credentials.
But i gave correct username password.
In local its working good.
What happen.?
hiii.. this example is very helpful for me for fecthing my gmail contact, but i also get my gmail profile information like my name, email,gender etc.. so how can i fecth this info in my application.. help me
hi Suresh, this example is very helpful for me for fetching my g-mail contact, I want to get online contact list from g-mail can you send me your suggestions and code to my mail-id kesavakumarv@gmail.com. Thanks in advance.
hi suresh...
can u post to import all latest email from inbox using gmail account.
Dear sir
I want to create an application like gtalk where automatical reply option is available for user
foreach (Contact t in f.Entries)
in this case i have error what shoiuld i do? i need ur answers guys.........
Hi Sir,
thank you very much. for this article.
hello,I am Sagar J
my all contacts are importing when i run my project on local host,but when i publish the web application on server it gives me error 'Invalid Credentials'
my code is as below--
//Provide Login Information
RequestSettings rsLoginInfo = new RequestSettings("http://demo.vishwainfosoft.com/TalentAcquisition/TA_Home.aspx", txtGEmail.Text, txtPassword.Text);
rsLoginInfo.AutoPaging = true;
// Fetch contacts and dislay them in ListBox
ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);
Feed feedContacts = cRequest.GetContacts();
try
{
foreach (Contact gmailAddresses in feedContacts.Entries)
{
Console.WriteLine("\t" + gmailAddresses.Title);
//lstContacts.Items.Add(gmailAddresses.Title);
//chklContacts.DataBind();
foreach (EMail emailId in gmailAddresses.Emails)
{
Console.WriteLine("\t" + emailId.Address);
//lstContacts.Items.Add(" " + emailId.Address);
chklContacts.Items.Add(emailId.Address);
ViewState["TCount"] = chklContacts.Items.Count;
foreach (ListItem item in chklContacts.Items)
item.Selected = true;
lblTotalContacts.Text = "Total" + " " + ViewState["TCount"].ToString() + " " + "records found...";
}
}
}
catch(Exception ex)
{
lblTotalContacts.Text = ex.Message;
}
chklContacts.DataBind();
Great Article.. I just tried it out and worked like a charm..
The only confusion I have is that, if contacts can be imported from gmail using the method you have shared, what is the benefit of using the Google Contact API via OAuth 2.0 and access tokens?
Would really appreciate if you could throw some light on this.
Thanks a lot.
Hi Suresh,
I have tried your code and it can extract gmail contacts successfully when it is running from local machine (India location) but when trying to upload server and trying to extract then gmail suspecting its suspicious attempt and blocking login.
Do you have any information how to solve this problem?
Thanks for writing so many codes for others.
Suman
Hi sir,I have tried ur code it is working fine but i want to extract the contacts of yahoo also.how it can be done?
Do you have any information regarding this problem?
Hi sir,I have tried ur code it is working fine but i want to extract the contacts of yahoo also.how it can be done?
Do you have any information regarding this problem?
Hi,
Can u provide the API for Yahoo and Hotmail also.
<a href="http://hotmail.com" target="_blank">Hotmail</a>
Hi Sir
This very good and awesome article
Can you write program like this for Invite Facebook and twitter and LinkedIn contracts?? and publish us please??
hiiiii... suresh
I want to show all mails into my own site, so any code for this probelm
helo
I want to store all gmail in dtabase.
any help?
Thanks In advance
How to import Facebook and MSN and yahoo contacts in c# using asp.net please sent me details in this id:emails4boopalan@gmail.com ,,i am awaiting bosss...
Very insightful idea. thanks.